Skip to content

Commit

Permalink
fixup! Fix 12681: FP: knownConditionTrueFalse
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-berder committed May 20, 2024
1 parent 5b7342f commit 12e80ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 2 additions & 9 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,15 +2838,8 @@ struct ValueFlowAnalyzer : Analyzer {

/* Handle overflow/underflow for value bounds */
if (value->bound != ValueFlow::Value::Bound::Point) {
if (newvalue > value->intvalue) {
if ((inc && value->bound == ValueFlow::Value::Bound::Lower)
|| (!inc && value->bound == ValueFlow::Value::Bound::Upper))
value->invertBound();
} else if (newvalue < value->intvalue) {
if ((!inc && value->bound == ValueFlow::Value::Bound::Lower)
|| (inc && value->bound == ValueFlow::Value::Bound::Upper))
value->invertBound();
}
if ((newvalue > value->intvalue && !inc) || (newvalue < value->intvalue && inc))
value->invertBound();
}

value->intvalue = newvalue;
Expand Down
10 changes: 9 additions & 1 deletion test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4784,14 +4784,22 @@ class TestCondition : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout_str());

// #12681
// #12681
check("void f(unsigned u) {\n"
" if (u > 0) {\n"
" u--;\n"
" if (u == 0) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(unsigned u) {\n"
" if (u < 0xFFFFFFFF) {\n"
" u++;\n"
" if (u == 0xFFFFFFFF) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueInfer() {
Expand Down

0 comments on commit 12e80ec

Please sign in to comment.