Uninitialized variables: Fixed false positives for loops. Ticket: #3369
This commit is contained in:
parent
8e3e634ce0
commit
63e2f64b9c
|
@ -1115,6 +1115,12 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: handle loops etc
|
||||||
|
if (Token::simpleMatch(tok, ") {")) {
|
||||||
|
ret = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "return|break|continue|throw"))
|
if (Token::Match(tok, "return|break|continue|throw"))
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
|
|
|
@ -1754,6 +1754,16 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// for, while
|
||||||
|
checkUninitVar2("void f() {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" while (a) {\n"
|
||||||
|
" if (b) x++;\n"
|
||||||
|
" else x = 0;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// exit
|
// exit
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue