diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d929b15ad..78bf5d98f 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -91,8 +91,13 @@ private: std::list::const_iterator it; for (it = checks.begin(); it != checks.end(); ++it) { UninitVar *c = dynamic_cast(*it); - if (c && c->varId == varid) - c->alloc = true; + if (c && c->varId == varid) { + if (c->pointer) + c->alloc = true; + else + bailOutVar(checks, varid); + break; + } } } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index e6d036fb4..706d137e0 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1300,6 +1300,13 @@ private: " char c = *s;\n" "};\n"); ASSERT_EQUALS("[test.cpp:6]: (error) Data is allocated but not initialized: s\n", errout.str()); + + // #3708 - false positive when using ptr typedef + checkUninitVar("void f() {\n" + " uintptr_t x = malloc(100);\n" + " uintptr_t y = x + 10;\n" // <- not bad usage + "}\n"); + ASSERT_EQUALS("", errout.str()); } // class / struct..