From d88c236efe3c970520b55a69b7120acebd484d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 7 Nov 2009 14:54:12 +0100 Subject: [PATCH] uninitialized data: minor fix to handle 'new char [' better --- lib/checkother.cpp | 4 +++- test/testother.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a30794c3e..d7ed416b0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1422,7 +1422,9 @@ void CheckOther::uninitvar() continue; // goto ')' - tok = tok->tokAt(4)->link(); + tok = tok->tokAt(4); + if (tok->str() == "(") + tok = tok->link(); if (!tok) break; diff --git a/test/testother.cpp b/test/testother.cpp index 0b06e5771..a2e0e7a34 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1145,6 +1145,12 @@ private: "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char *s1 = new char[10];\n" + " char *s2 = new char[strlen(s1)];\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str()); }