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;
|
||||
}
|
||||
|
||||
// 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..
|
||||
if (Token::Match(tok, "if (")) {
|
||||
// initialization in condition..
|
||||
|
|
|
@ -1775,6 +1775,15 @@ private:
|
|||
"}\n");
|
||||
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
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
|
|
Loading…
Reference in New Issue