diff --git a/lib/infer.cpp b/lib/infer.cpp index c06631cdd..c925ef3bc 100644 --- a/lib/infer.cpp +++ b/lib/infer.cpp @@ -148,7 +148,7 @@ struct Interval { result.setMinValue(minValue->intvalue + 1, minValue); if (minValue->isPossible() && minValue->bound == ValueFlow::Value::Bound::Lower) result.setMinValue(minValue->intvalue, minValue); - if (!minValue->isImpossible() && minValue->bound == ValueFlow::Value::Bound::Point && + if (!minValue->isImpossible() && (minValue->bound == ValueFlow::Value::Bound::Point || minValue->isKnown()) && std::count_if(values.begin(), values.end(), predicate) == 1) return Interval::fromInt(minValue->intvalue, minValue); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 87c9cedea..b36b82eb7 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7183,6 +7183,17 @@ private: " a;\n" "}\n"; valueOfTok(code, "a"); + + code = "void f(int i, int j, int n) {\n" + " if ((j == 0) != (i == 0)) {}\n" + " int t = 0;\n" + " if (j > 0) {\n" + " t = 1;\n" + " if (n < j)\n" + " n = j;\n" + " }\n" + "}\n"; + valueOfTok(code, "i"); } void valueFlowCrashConstructorInitialization() { // #9577