Uninitialized variables: Fixed false positives when many 'if' are used. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-16 19:56:13 +01:00
parent a311904a0f
commit 5f1fadec7b
2 changed files with 16 additions and 1 deletions

View File

@ -1062,6 +1062,9 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
for (; tok; tok = tok->next()) {
// End of scope..
if (tok->str() == "}") {
if (number_of_if)
return true;
// might be a noreturn function..
if (Token::simpleMatch(tok->tokAt(-2), ") ; }") &&
Token::Match(tok->linkAt(-2)->tokAt(-2), "[;{}] %var% (") &&

View File

@ -1753,7 +1753,7 @@ private:
" else if (y == 2) { x = 1; }\n"
" return x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", "", errout.str());
// initialization in condition
checkUninitVar2("void f() {\n"
@ -1839,6 +1839,18 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int a,b=0;\n"
" if (x) {\n"
" if (y) {\n"
" a = 0;\n"
" b = 1;\n"
" }\n"
" }\n"
" if (b) a++;\n"
"}");
ASSERT_EQUALS("", errout.str());
// asm
checkUninitVar2("void f() {\n"
" int x;\n"