From c150317f026551cbec80a3c229bd883a2bb35c74 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 9 Dec 2022 00:15:15 -0600 Subject: [PATCH] Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement (#4625) * Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement * Format --- lib/valueflow.cpp | 2 +- test/testcondition.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 061634479..2838265eb 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6070,7 +6070,7 @@ struct ConditionHandler { }); for (Token* start:nextExprs) { Analyzer::Result r = forward(start, cond.vartok, values, tokenlist); - if (r.terminate != Analyzer::Terminate::None) + if (r.terminate != Analyzer::Terminate::None || r.action.isModified()) return; } } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index fea1faebc..974637af0 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4640,6 +4640,13 @@ private: " if (i == j) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #11384 + check("bool f(const int* it, const int* end) {\n" + " return (it != end) && *it++ &&\n" + " (it != end) && *it;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {