From 06ee643c6a6fb16e3ca912f7eea7e0b215adf6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Dec 2009 11:32:46 +0100 Subject: [PATCH] Fixed #1177 (False positive: pointer is not dereferenced 'sizeof(*p)') --- lib/checkother.cpp | 3 +++ test/testother.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1ec1994a2..abd8171e9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1557,6 +1557,9 @@ private: if (Token::Match(&tok, "%var% (")) { + if (Token::simpleMatch(&tok, "sizeof (")) + return tok.next()->link(); + // deallocate pointer if (Token::Match(&tok, "free|kfree|fclose ( %var% )")) { diff --git a/test/testother.cpp b/test/testother.cpp index 535feb6ae..67382544a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1274,6 +1274,13 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " Abc *p;\n" + " int sz = sizeof(*p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // arrays.. checkUninitVar("void f()\n" "{\n"