Uninitialized variables: Another fix for false positives when it's known that inner conditions are true

This commit is contained in:
Daniel Marjamäki 2012-02-06 19:26:28 +01:00
parent 05fc77c347
commit 47c7e346aa
2 changed files with 12 additions and 2 deletions

View File

@ -1113,8 +1113,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
}
// assignment with nonzero constant..
if (Token::Match(tok, "[;{}] %var% = - %var% ;") && tok->next()->varId() > 0)
notzero.insert(tok->next()->varId());
if (Token::Match(tok->previous(), "[;{}] %var% = - %var% ;") && tok->varId() > 0)
notzero.insert(tok->varId());
// Inner scope..
if (Token::simpleMatch(tok, "if (")) {

View File

@ -1893,6 +1893,16 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int i, y;\n"
" if (x) {\n"
" y = -ENOMEM;\n"
" if (y != 0) return;\n"
" i++;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// for, while
checkUninitVar2("void f() {\n"
" int x;\n"