Uninitialized variables: Fixed false positive in for condition. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-15 20:48:26 +01:00
parent 40f2f4f7f6
commit d2d7e25f3f
2 changed files with 9 additions and 1 deletions

View File

@ -1124,7 +1124,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
}
// TODO: handle loops, try, etc
if (Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
return true;
}

View File

@ -1792,6 +1792,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int x;\n"
" for (int i = 0; i < 10; i += x) {\n"
" x = y;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// try
checkUninitVar2("void f() {\n"
" int i, *p = &i;\n"