From b6c320de8a72b6a1f928fa8428e59cd030d32881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 23 Dec 2009 15:01:23 +0100 Subject: [PATCH] Fixed false positives about uninitialized variables --- lib/checkother.cpp | 2 ++ test/testother.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8f929232e..36efe94c6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1286,6 +1286,8 @@ private: static void use(bool &foundError, std::list &checks, const Token *tok, const int mode) { const unsigned int varid(tok->varId()); + if (varid == 0) + return; std::list::const_iterator it; for (it = checks.begin(); it != checks.end(); ++it) diff --git a/test/testother.cpp b/test/testother.cpp index cf9a1abc6..1ee858fad 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1315,6 +1315,13 @@ private: " strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void foo()\n" + "{\n" + " const std::string s(x());\n" + " strchr(s.c_str(), ',');\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }