From bfd8a69e74f88826940eccd1bf9ab29a6a0f13ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 27 Oct 2015 12:40:52 +0100 Subject: [PATCH] Fixed #6243 (False positive: uninitialized variable, looping with goto) --- lib/checkuninitvar.cpp | 5 +++++ test/testuninitvar.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 62afbafc6..33bfaaca5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9a8b88f4a..57673d834 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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"