Fix 10362: ValueFlow: global variable might be modified by function call (#3358)

This commit is contained in:
Paul Fultz II 2021-07-26 15:21:56 -05:00 committed by GitHub
parent c14bb9cd2e
commit 14802b932e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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() {