Fix 10543: FP knownConditionTrueFalse with static variable (#3491)

This commit is contained in:
Paul Fultz II 2021-10-09 09:20:04 -05:00 committed by GitHub
parent a1e0ef9b38
commit bc90ae889d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -4378,6 +4378,13 @@ static void valueFlowSymbolic(TokenList* tokenlist, SymbolDatabase* symboldataba
} else if (isDifferentType(tok->astOperand2(), tok->astOperand1())) {
continue;
}
const std::vector<const Variable*> vars = getLHSVariables(tok);
if (std::any_of(vars.begin(), vars.end(), [](const Variable* var) {
if (var->isLocal())
return var->isStatic();
return !var->isArgument();
}))
continue;
Token* start = nextAfterAstRightmostLeaf(tok);
const Token* end = scope->bodyEnd;

View File

@ -3857,6 +3857,17 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int get_delta() {\n"
" clock_t now_ms = (clock() / (CLOCKS_PER_SEC / 1000));\n"
" static clock_t last_clock_ms = now_ms;\n"
" clock_t delta = now_ms - last_clock_ms;\n"
" last_clock_ms = now_ms;\n"
" if (delta > 50)\n"
" delta = 50;\n"
" return delta;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueInfer() {