Uninitialized variables: Fixed false positives for unconditional inner scopes

This commit is contained in:
Daniel Marjamäki 2011-12-26 17:52:32 +01:00
parent 025518c474
commit c56e2e7cf9
2 changed files with 17 additions and 0 deletions

View File

@ -1103,6 +1103,14 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
break;
}
// Unconditional inner scope..
if (tok->str() == "{" && Token::Match(tok->previous(), "[;{}]")) {
if (checkScopeForVariable(tok->next(), varid, ispointer, possibleInit))
return true;
tok = tok->link();
continue;
}
// Inner scope..
if (Token::Match(tok, "if (")) {
// initialization in condition..

View File

@ -1775,6 +1775,15 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// unconditional initialization
checkUninitVar2("int f() {\n"
" int ret;\n"
" if (a) { ret = 1; }\n"
" else { {} ret = 2; }\n"
" return ret;\n"
"}");
ASSERT_EQUALS("", errout.str());
// conditional initialization
checkUninitVar2("void f() {\n"
" int x;\n"