From 4abbe9ffd4e22bb3451eb6f05e3575fcaa29d33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Nov 2009 16:28:15 +0100 Subject: [PATCH] Fixed #889 (false positive: uninitialized variable) --- lib/checkother.cpp | 9 ++++++--- test/testother.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5b73c007a..b7d48b614 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1287,10 +1287,13 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va } } - if (Token::Match(tok, "%varid% =", varid)) + if (Token::Match(tok, "%varid%", varid)) { - init = true; - return 0; + if (Token::simpleMatch(tok->previous(), ">>") || Token::simpleMatch(tok->next(), "=")) + { + init = true; + return 0; + } } if (Token::Match(tok, "%var% (")) diff --git a/test/testother.cpp b/test/testother.cpp index abe3fc2c4..52e61599e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -973,6 +973,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a()\n" + "{\n" + " int ret;\n" + " std::cin >> ret;\n" + " return ret;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // if.. checkUninitVar("static void foo()\n" "{\n"