From 016793f258466a0424bfab4f77c3fa8e12097bee Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 6 Sep 2022 00:31:38 -0500 Subject: [PATCH] Fix 11295: Regression FP: knownConditionTrueFalse (#4443) --- lib/checkcondition.cpp | 4 +++- test/testcondition.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index b0466994b..a9e629197 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1494,7 +1494,9 @@ void CheckCondition::alwaysTrueFalse() continue; if (!isUsedAsBool(tok)) continue; - if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%|%assign%")) + if (Token::simpleMatch(condition, "return") && Token::Match(tok, "%assign%")) + continue; + if (Token::simpleMatch(tok->astParent(), "return") && Token::Match(tok, ".|%var%")) continue; if (Token::Match(tok, "%num%|%bool%|%char%")) continue; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 3ac059b7e..40711e5f0 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4341,6 +4341,13 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'f()' is always true\n" "[test.cpp:4]: (style) Condition 'f()==3' is always true\n", errout.str()); + + check("int f() {\n" + " const char *n;\n" + " return((n=42) &&\n" + " *n == 'A');\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic()