From 566cfce8da112c408da22af242e2945e2e57cb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 22 Dec 2009 21:00:52 +0100 Subject: [PATCH] Fixed #1128 (false positive: Data is allocated but not initialized) --- lib/checkother.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 77ec55a7f..0870d836b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1361,7 +1361,7 @@ private: return &tok; } - if (Token::Match(tok.next(), "= malloc|kmalloc|new")) + if (Token::Match(tok.next(), "= malloc|kmalloc") || Token::simpleMatch(tok.next(), "= new char [")) { alloc_pointer(checks, tok.varId()); } diff --git a/test/testother.cpp b/test/testother.cpp index 254f9085a..835edbe00 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1256,6 +1256,13 @@ private: "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " Fred *fred = new Fred;\n" + " fred->foo();\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + // struct.. checkUninitVar("void f()\n" "{\n"