diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 1eb7c620e48..07b30a86cdb 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 3a7d9ab41fa..f488bdadf90 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4784,7 +4784,7 @@ class TestCondition : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - // #12681 + // #12681 check("void f(unsigned u) {\n" " if (u > 0) {\n" " u--;\n" @@ -4792,6 +4792,14 @@ class TestCondition : public TestFixture { " }\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() {