From 53f7b12b4f0b77243fb52eb46c2171888ef3d9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 6 Nov 2009 16:02:13 +0100 Subject: [PATCH] Fixed #902 (false positive: uninitialized variable when variable is initialized in macro) --- lib/checkother.cpp | 11 +++++++++++ test/testother.cpp | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2539e379f..38991a89e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1343,6 +1343,17 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token } } + if (tok->str() == "return") + { + for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) + { + if (tok2->str() == ";") + return 0; + if (tok2->varId() == varid) + break; + } + } + if (tok->varId() == varid) { if (Token::simpleMatch(tok->previous(), "return")) diff --git a/test/testother.cpp b/test/testother.cpp index 8f153e08f..0808ac951 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1010,6 +1010,23 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + // goto.. + checkUninitVar("void foo(int x)\n" + "{\n" + " long b;\n" + " if (g()) {\n" + " b =2;\n" + " goto found;\n" + " }\n" + "\n" + " return;\n" + "\n" + "found:\n" + " int a = b;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + // if.. checkUninitVar("static void foo()\n" "{\n"