Skip to content

Commit

Permalink
Fix #12727 FP knownConditionTrueFalse (wrong range of return values) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 25, 2024
1 parent b8005e1 commit 04f7a9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ static bool isIntegralValue(const ValueFlow::Value& value)
static ValueFlow::Value evaluate(const std::string& op, const ValueFlow::Value& lhs, const ValueFlow::Value& rhs)
{
ValueFlow::Value result;
combineValueProperties(lhs, rhs, result);
if (lhs.isImpossible() && rhs.isImpossible())
return ValueFlow::Value::unknown();
if (lhs.isImpossible() || rhs.isImpossible()) {
Expand Down
16 changes: 16 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5108,6 +5108,22 @@ class TestCondition : public TestFixture {
" if ((128 + i < 255 ? 128 + i : 255) > 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("struct S {\n" // #12727
" bool f() const {\n"
" return g() > 0;\n"
" }\n"
" std::size_t g() const {\n"
" return 5 - h();\n"
" }\n"
" std::size_t h() const {\n"
" if (x > 7)\n"
" return 5;\n"
" return (5 + x) % 5;\n"
" }\n"
" std::size_t x;\n"
"};\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueContainer() {
Expand Down

0 comments on commit 04f7a9b

Please sign in to comment.