diff --git a/lib/checkother.cpp b/lib/checkother.cpp index af6fe1bc4..73c7a8993 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1415,7 +1415,7 @@ private: CheckUninitVar *c = dynamic_cast(*it); if (c && c->varId == varid) { - if (mode == 0 && c->array) + if (mode == 0 && (c->array || (c->pointer && c->alloc))) continue; if (mode == 2 && !c->pointer) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 0ea7f141d..31de8f0a1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1080,6 +1080,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo()\n" + "{\n" + " char *buf = malloc(100);\n" + " struct ABC *abc = buf;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // goto.. checkUninitVar("void foo(int x)\n" "{\n"