From c7ce87d060f12f7e55624636dd468af42bb68042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 14 Dec 2011 05:45:52 +0100 Subject: [PATCH] Uninitialized variables: Fixed false positives for break/continue/throw --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 802c89a0e..118793d4b 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1105,7 +1105,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int } } - if (tok->str() == "return") + if (Token::Match(tok, "return|break|continue|throw")) ret = true; // variable is seen.. diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 91622513f..f0d7940bf 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1708,14 +1708,18 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str()); + // return, break, continue checkUninitVar2("void f() {\n" " int x;\n" " if (y == 1) { return; }\n" + " if (y == 2) { break; }\n" + " if (y == 3) { continue; }\n" " else { x = 1; }\n" " return x;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + // exit checkUninitVar2("void f() {\n" " int x;\n" " if (y == 1) { exit(0); }\n"