diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 6cf189e24..04db01b8f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6304,7 +6304,7 @@ struct ConditionHandler { values.insert(values.end(), cond.false_values.cbegin(), cond.false_values.cend()); // extra logic for unsigned variables 'i>=1' => possible value can also be 0 - if (Token::Match(tok, "<|>")) { + if (Token::Match(tok, "<|>|<=|>=")) { values.remove_if([](const ValueFlow::Value& v) { if (v.isIntValue()) return v.intvalue != 0; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 2c3a77e3a..b2dc0da31 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4547,6 +4547,14 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int f(int i) {\n" // #11741 + " i = -i - 1;\n" + " if (i < 0 || i >= 20)\n" + " return 0;\n" + " return 1;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic() diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index df9f50dcd..4eac02e21 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1460,7 +1460,7 @@ private: " int a = x;\n" " if (x >= 1) {}\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 2U, 1)); + TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2U, 1)); ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); code = "void f(unsigned int x) {\n"