diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 860875963..348b71ec6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4545,14 +4545,14 @@ static std::vector infer(const ValuePtr& model, if (!diff.minvalue.empty()) { ValueFlow::Value value(diff.minvalue.front() - 1); value.setImpossible(); - value.bound = ValueFlow::Value::Bound::Lower; + value.bound = ValueFlow::Value::Bound::Upper; addToErrorPath(value, diff.minRef); result.push_back(value); } if (!diff.maxvalue.empty()) { ValueFlow::Value value(diff.maxvalue.front() + 1); value.setImpossible(); - value.bound = ValueFlow::Value::Bound::Upper; + value.bound = ValueFlow::Value::Bound::Lower; addToErrorPath(value, diff.maxRef); result.push_back(value); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 417aab5b8..cbee6cc8a 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3787,6 +3787,14 @@ private: check("bool f(bool a, bool b) { if(a && b && (!a)){} }"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition '!a' is always false\n", errout.str()); + check("void f(int x, int y) {\n" + " if (x < y) {\n" + " auto z = y - x;\n" + " if (z < 1) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'z<1' is always false\n", errout.str()); + check("struct a {\n" " a *b() const;\n" "} c;\n"