Uninitialized variables: Fixed false positives for such code: 'if (cond1) { a=0; } if (cond1) { if (cond2) { use_a; } }'
This commit is contained in:
parent
987392f254
commit
7c606c4e3b
|
@ -1123,7 +1123,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
// goto the {
|
||||
tok = tok->next()->link()->next();
|
||||
|
||||
bool possibleInitIf(number_of_if > 0);
|
||||
bool possibleInitIf(number_of_if > 0 || suppressErrors);
|
||||
const bool initif = checkScopeForVariable(tok->next(), varid, ispointer, &possibleInitIf);
|
||||
|
||||
// goto the }
|
||||
|
@ -1143,7 +1143,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
// goto the {
|
||||
tok = tok->tokAt(2);
|
||||
|
||||
bool possibleInitElse(number_of_if > 0);
|
||||
bool possibleInitElse(number_of_if > 0 || suppressErrors);
|
||||
const bool initelse = checkScopeForVariable(tok->next(), varid, ispointer, &possibleInitElse);
|
||||
|
||||
// goto the }
|
||||
|
|
|
@ -1952,6 +1952,20 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int a;\n"
|
||||
" if (x) { a = 0; }\n"
|
||||
" if (x) { if (y) { a++; } }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int a;\n"
|
||||
" if (x) { a = 0; }\n"
|
||||
" if (x) { if (y) { } else { a++; } }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// asm
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
|
|
Loading…
Reference in New Issue