From 9aca2e7680aa084e949f0f93d38966c22f63783b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 28 Dec 2009 12:51:28 +0100 Subject: [PATCH] Fixed #1156 ([False positive] Uninitialized variable - class member in constructor) --- lib/checkother.cpp | 2 ++ test/testother.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ea956fbc9..498425beb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1375,6 +1375,8 @@ private: static void dealloc_pointer(bool &foundError, std::list &checks, const Token *tok) { const unsigned int varid(tok->varId()); + if (!varid) + 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 4b950a6b7..daa0f393b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1094,6 +1094,17 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("class Fred {\n" + "public:\n" + " FILE *f;\n" + " ~Fred();\n" + "}\n" + "Fred::~Fred()\n" + "{\n" + " fclose(f);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // goto.. checkUninitVar("void foo(int x)\n" "{\n"