Fixed #6243 (False positive: uninitialized variable, looping with goto)

This commit is contained in:
Daniel Marjamäki 2015-10-27 12:40:52 +01:00
parent 4b0625c570
commit bfd8a69e74
2 changed files with 15 additions and 0 deletions

View File

@ -484,6 +484,11 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
return true;
}
// bailout if there is a goto label
if (Token::Match(tok, "[;{}] %name% :")) {
return true;
}
if (tok->str() == "?") {
if (!tok->astOperand2())
return true;

View File

@ -611,6 +611,16 @@ private:
"}", "test.cpp", false);
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo() {\n"
" int x,y=0;\n"
"again:\n"
" if (y) return x;\n"
" x = a;\n"
" y = 1;\n"
" goto again;\n"
"}", "test.c", false);
ASSERT_EQUALS("", errout.str());
// Ticket #3873 (false positive)
checkUninitVar("MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {\n"
" MachineLoopRange *&Range = Cache[Loop];\n"