From fc7f78244e524406dc5414b1880fec3f473c8edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 14 May 2012 18:34:39 +0200 Subject: [PATCH] Fixed #3708 (False positive: uninitialized variable (allocation, unknown nonpointer type)) --- lib/checkuninitvar.cpp | 9 +++++++-- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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..