From a639c5978089f82f895075a01e4c45a6154b374b Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 6 Feb 2022 13:13:44 -0600 Subject: [PATCH] Fix 10787: False positive: knownConditionTrueFalse with a conditional exit (#3804) --- lib/symboldatabase.cpp | 2 ++ test/testvalueflow.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 47bb77ccf..ee1f58eb7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1439,6 +1439,8 @@ void SymbolDatabase::createSymbolDatabaseEscapeFunctions() Function * function = scope.function; if (!function) continue; + if (Token::findsimplematch(scope.bodyStart, "return", scope.bodyEnd)) + continue; function->isEscapeFunction(isReturnScope(scope.bodyEnd, &mSettings->library, nullptr, true)); } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ee326ff61..02e885c05 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3133,6 +3133,19 @@ private: "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 8U, 1)); ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 1)); + + code = "void g(int i) {\n" + " if (i == 1)\n" + " return;\n" + " abort();\n" + "}\n" + "int f(int x) {\n" + " if (x != 0)\n" + " g(x);\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(false, testValueOfXKnown(code, 9U, 0)); + ASSERT_EQUALS(true, testValueOfX(code, 9U, 0)); } void valueFlowAfterConditionExpr() {