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 24, 2024
1 parent a9e479a commit fba5307
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 @@ -579,7 +579,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 @@ -4988,6 +4988,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 fba5307

Please sign in to comment.