Uninitialized variables: Fixed false positives for loops. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-14 18:54:03 +01:00
parent 8e3e634ce0
commit 63e2f64b9c
2 changed files with 16 additions and 0 deletions

View File

@ -1115,6 +1115,12 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
} }
} }
// TODO: handle loops etc
if (Token::simpleMatch(tok, ") {")) {
ret = true;
return false;
}
if (Token::Match(tok, "return|break|continue|throw")) if (Token::Match(tok, "return|break|continue|throw"))
ret = true; ret = true;

View File

@ -1754,6 +1754,16 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// for, while
checkUninitVar2("void f() {\n"
" int x;\n"
" while (a) {\n"
" if (b) x++;\n"
" else x = 0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// exit // exit
checkUninitVar2("void f() {\n" checkUninitVar2("void f() {\n"
" int x;\n" " int x;\n"