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"