From 39614a699e419da6faa5df993db42ba6cd53fa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 10 Nov 2009 19:35:54 +0100 Subject: [PATCH] Uninitialized variables: detect uninitialized pointer array --- lib/checkclass.cpp | 6 ++++++ test/testclass.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 22bc73edd..c97793a3f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -138,6 +138,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses) varname = next->strAt(1); } + // Pointer array? + else if (Token::Match(next, "%type% * %var% [")) + { + varname = next->strAt(2); + } + // std::string.. else if (withClasses && Token::Match(next, "std :: string %var% ;")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 61e7036f6..549ea5369 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -445,6 +445,15 @@ private: " A a[5];\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("class A;\n" + "class John\n" + "{\n" + "public:\n" + " John() { }\n" + " A *a[5];\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'John::a'\n", errout.str()); } void uninitMissingFuncDef()