Skip to content

Commit bfd8a69

Browse files
committed
Fixed danmar#6243 (False positive: uninitialized variable, looping with goto)
1 parent 4b0625c commit bfd8a69

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/checkuninitvar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
484484
return true;
485485
}
486486

487+
// bailout if there is a goto label
488+
if (Token::Match(tok, "[;{}] %name% :")) {
489+
return true;
490+
}
491+
487492
if (tok->str() == "?") {
488493
if (!tok->astOperand2())
489494
return true;

test/testuninitvar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,16 @@ class TestUninitVar : public TestFixture {
611611
"}", "test.cpp", false);
612612
ASSERT_EQUALS("", errout.str());
613613

614+
checkUninitVar("int foo() {\n"
615+
" int x,y=0;\n"
616+
"again:\n"
617+
" if (y) return x;\n"
618+
" x = a;\n"
619+
" y = 1;\n"
620+
" goto again;\n"
621+
"}", "test.c", false);
622+
ASSERT_EQUALS("", errout.str());
623+
614624
// Ticket #3873 (false positive)
615625
checkUninitVar("MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {\n"
616626
" MachineLoopRange *&Range = Cache[Loop];\n"

0 commit comments

Comments
 (0)