From ec6d66ff45f71ca0e9b637f6dd557c4a881839a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 14 Nov 2009 08:00:17 +0100 Subject: [PATCH] Fixed #913 (false positive: uninitialized variable) --- lib/checkother.cpp | 4 +++- test/testother.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bd02851e1..7774f035c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1203,9 +1203,11 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token return 0; } - if (Token::Match(tok, "= {")) + if (Token::Match(tok, "= {|(")) { tok = tok->next()->link(); + if (Token::simpleMatch(tok, ") {")) + tok = tok->next()->link(); if (!tok) { init = true; diff --git a/test/testother.cpp b/test/testother.cpp index 6c8da0384..0bf3fa861 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1062,6 +1062,22 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int foo()\n" + "{\n" + " int i;\n" + " if (x)\n" + " {\n" + " struct abc abc1 = (struct abc) { .a=0, .b=0, .c=0 };\n" + " i = 22;\n" + " }\n" + " else\n" + " {\n" + " i = 33;\n" + " }\n" + " return i;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("static void foo()\n" "{\n" " Foo *p;\n"