From 37ae4692bbf2c55c5fc4cb284219e0ae5cbac943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 May 2010 10:30:51 +0200 Subject: [PATCH] Uninitialized variables: fixed false negative when using uninitialized variable inside malloc call --- 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 dddc70a9f..f6b25f855 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2960,7 +2960,7 @@ private: { alloc_pointer(checks, tok.varId()); if (tok.tokAt(3)->str() == "(") - return tok.tokAt(3)->link(); + return tok.tokAt(3); } else if (Token::simpleMatch(tok.previous(), ">>") || Token::simpleMatch(tok.next(), "=")) diff --git a/test/testother.cpp b/test/testother.cpp index b695a797f..e342d3ae0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1176,6 +1176,13 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + checkUninitVar("void f(Foo *p)\n" + "{\n" + " int a;\n" + " p->a = malloc(4 * a);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str()); + checkUninitVar("static void foo()\n" "{\n" " int *p;\n"