Fix another FP with range for macro (#3276)

This commit is contained in:
Paul Fultz II 2021-05-25 21:52:55 -05:00 committed by GitHub
parent a4653a057a
commit 5f0fe1dfe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -1909,6 +1909,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
} }
if (Token::simpleMatch(tok2->astParent(), ":") && tok2->astParent()->astParent() && Token::simpleMatch(tok2->astParent()->astParent()->previous(), "for (")) { if (Token::simpleMatch(tok2->astParent(), ":") && tok2->astParent()->astParent() && Token::simpleMatch(tok2->astParent()->astParent()->previous(), "for (")) {
// TODO: Check if container is empty or not
if (astIsLHS(tok2))
return true;
const Token * varTok = tok2->astParent()->previous(); const Token * varTok = tok2->astParent()->previous();
if (!varTok) if (!varTok)
return false; return false;

View File

@ -1528,8 +1528,6 @@ void CheckUninitVar::valueFlowUninit()
continue; continue;
if (v->indirect > 1 || v->indirect < 0) if (v->indirect > 1 || v->indirect < 0)
continue; continue;
if (v->indirect == 0 && !isVariableUsage(tok, tok->valueType() && tok->valueType()->pointer > 0, NO_ALLOC))
continue;
bool uninitderef = false; bool uninitderef = false;
if (tok->variable()) { if (tok->variable()) {
bool unknown; bool unknown;

View File

@ -4646,6 +4646,16 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
valueFlowUninit("X f() {\n"
" if (!itemList.empty()) {\n"
" X* item;\n"
" for(item: itemList) {}\n"
" return *item;\n"
" }\n"
" return X{};\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// macro_for.. // macro_for..
valueFlowUninit("int foo()\n" valueFlowUninit("int foo()\n"
"{\n" "{\n"