Uninitialized variables: Another fix for false positives when it's known that inner conditions are true
This commit is contained in:
parent
05fc77c347
commit
47c7e346aa
|
@ -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 (")) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue