From 14802b932e4b05f5bdaeb6762a655ed6846a237e Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 26 Jul 2021 15:21:56 -0500 Subject: [PATCH] Fix 10362: ValueFlow: global variable might be modified by function call (#3358) --- lib/forwardanalyzer.cpp | 2 +- test/testcondition.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 7a1fd2afb..fdf324e7e 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -382,7 +382,7 @@ struct ForwardTraversal { bool checkThen = true; bool checkElse = false; if (condTok && !Token::simpleMatch(condTok, ":")) - std::tie(checkThen, checkElse) = evalCond(condTok, isDoWhile ? endBlock->link()->previous() : nullptr); + std::tie(checkThen, checkElse) = evalCond(condTok, isDoWhile ? endBlock->previous() : nullptr); if (checkElse && exit) return Progress::Continue; // do while(false) is not really a loop diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7503b76f0..e94f3d106 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3671,6 +3671,23 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10362 + check("int tok;\n" + "void next();\n" + "void parse_attribute() {\n" + " if (tok == '(') {\n" + " int parenthesis = 0;\n" + " do {\n" + " if (tok == '(')\n" + " parenthesis++;\n" + " else if (tok == ')')\n" + " parenthesis--;\n" + " next();\n" + " } while (parenthesis && tok != -1);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {