Fixed #3417 (False positive: Uninitialized variable when conditionally set)

This commit is contained in:
Daniel Marjamäki 2011-12-15 18:15:58 +01:00
parent 9e54714894
commit 005b1cff61
2 changed files with 12 additions and 0 deletions

View File

@ -1074,6 +1074,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
// Inner scope..
if (Token::Match(tok, "if (")) {
if (number_of_if) {
return true;
}
// initialization in condition..
const Token * const endToken = tok->next()->link();
for (const Token *tok2 = tok->tokAt(2); tok2 != endToken; tok2 = tok2->next()) {

View File

@ -1800,6 +1800,14 @@ private:
" for_each(i) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
// if, if
checkUninitVar2("void f(int a) {\n"
" int i;\n"
" if (a) i = 0;\n"
" if (a) i++;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};