From 025518c47446f9102ff0b53a3079b78e1252bc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 26 Dec 2011 16:46:10 +0100 Subject: [PATCH] Uninitialized variables: Fixed false positives when goto is used. --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d0d6e0b88..bc068fb01 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1182,7 +1182,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int return true; } - if (Token::Match(tok, "return|break|continue|throw")) + if (Token::Match(tok, "return|break|continue|throw|goto")) ret = true; else if (ret && tok->str() == ";") return true; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 23e0c00e7..72c589f3b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1801,7 +1801,7 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); - // return, break, continue + // return, break, continue, goto checkUninitVar2("void f() {\n" " int x;\n" " if (y == 1) { return; }\n" @@ -1820,6 +1820,17 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " int i;\n" + " if (x) {\n" + " i = 1;\n" + " } else {\n" + " goto out;\n" + " }\n" + " i++;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // for, while checkUninitVar2("void f() {\n" " int x;\n"