From 8d57cef7f9e450212d6ad045ad9158b0f78408cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Nov 2009 19:58:49 +0100 Subject: [PATCH] Fixed #764 (usage of unitialized variable not detected) --- lib/checkother.cpp | 5 +++-- test/testother.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b7d48b614..1ab3f6eaf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1331,13 +1331,14 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va if (Token::simpleMatch(tok->previous(), "return")) return tok; + if (Token::simpleMatch(tok->previous(), "=")) + return tok; + if (pointer && Token::simpleMatch(tok->next(), ".")) return tok; if (array && Token::simpleMatch(tok->next(), "[")) { - if (Token::simpleMatch(tok->previous(), "=")) - return tok; init = true; return 0; } diff --git a/test/testother.cpp b/test/testother.cpp index e16ef4dd5..c83f7c206 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -973,6 +973,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void a()\n" + "{\n" + " int x;\n" + " int y = x;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); + checkUninitVar("int a()\n" "{\n" " int ret;\n"