Fixed #3417 (False positive: Uninitialized variable when conditionally set)
This commit is contained in:
parent
9e54714894
commit
005b1cff61
|
@ -1074,6 +1074,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
|
|
||||||
// Inner scope..
|
// Inner scope..
|
||||||
if (Token::Match(tok, "if (")) {
|
if (Token::Match(tok, "if (")) {
|
||||||
|
if (number_of_if) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// initialization in condition..
|
// initialization in condition..
|
||||||
const Token * const endToken = tok->next()->link();
|
const Token * const endToken = tok->next()->link();
|
||||||
for (const Token *tok2 = tok->tokAt(2); tok2 != endToken; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(2); tok2 != endToken; tok2 = tok2->next()) {
|
||||||
|
|
|
@ -1800,6 +1800,14 @@ private:
|
||||||
" for_each(i) { }\n"
|
" for_each(i) { }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue