From ce2d23b67ade02d1fe7464c2c63c191f753dd0d2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 18 Apr 2023 10:17:14 -0500 Subject: [PATCH 1/2] Fix 11669: Assert failure in infer.cpp --- lib/infer.cpp | 2 +- test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/infer.cpp b/lib/infer.cpp index c06631cddac..c925ef3bc3a 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 87c9cedea98..8dec9436773 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7183,6 +7183,17 @@ class TestValueFlow : public TestFixture { " 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 From eaf0c318a6f42e506aa44dae20fe13bdba77104a Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 18 Apr 2023 10:19:20 -0500 Subject: [PATCH 2/2] Format --- test/testvalueflow.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8dec9436773..b36b82eb7a8 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7185,14 +7185,14 @@ class TestValueFlow : public TestFixture { 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"; + " 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"); }