Fixed #6243 (False positive: uninitialized variable, looping with goto)
This commit is contained in:
parent
4b0625c570
commit
bfd8a69e74
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue