Uninitialized variables: Fixed false positives for unconditional inner scopes
This commit is contained in:
parent
025518c474
commit
c56e2e7cf9
|
@ -1103,6 +1103,14 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unconditional inner scope..
|
||||||
|
if (tok->str() == "{" && Token::Match(tok->previous(), "[;{}]")) {
|
||||||
|
if (checkScopeForVariable(tok->next(), varid, ispointer, possibleInit))
|
||||||
|
return true;
|
||||||
|
tok = tok->link();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Inner scope..
|
// Inner scope..
|
||||||
if (Token::Match(tok, "if (")) {
|
if (Token::Match(tok, "if (")) {
|
||||||
// initialization in condition..
|
// initialization in condition..
|
||||||
|
|
|
@ -1775,6 +1775,15 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// unconditional initialization
|
||||||
|
checkUninitVar2("int f() {\n"
|
||||||
|
" int ret;\n"
|
||||||
|
" if (a) { ret = 1; }\n"
|
||||||
|
" else { {} ret = 2; }\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// conditional initialization
|
// conditional initialization
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue