From c37ba4cbcff366ec117bfd693c3b6523e6d0bf6e Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 12 Oct 2013 13:46:14 -0300 Subject: [PATCH 1/2] - Fixed false positive when using typeof/__alignof__ --- lib/checkuninitvar.cpp | 4 ++++ test/testuninitvar.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index b7095459a..22614f5dd 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1603,6 +1603,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp if (vartok->previous()->str() == "return") return true; + // Passing variable to typeof + if (Token::Match(vartok->tokAt(-3), "typeof|__alignof__ ( * %var%")) + return false; + // Passing variable to function.. if (Token::Match(vartok->previous(), "[(,] %var% [,)]") || Token::Match(vartok->tokAt(-2), "[(,] & %var% [,)]")) { const bool address(vartok->previous()->str() == "&"); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index f58617c9b..17cb06199 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1963,6 +1963,12 @@ private: " TYPEOF(s->status);\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f() {\n" + " #define w(x) ({ x z; (x*)z; })\n" + " int *n = w(typeof(*n));\n" + "}"); + ASSERT_EQUALS("", errout.str()); } From ed565f1ab1fed85f57362516cdd9734a10040411 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 12 Oct 2013 13:49:35 -0300 Subject: [PATCH 2/2] - Fix comment --- lib/checkuninitvar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 22614f5dd..f31da168e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1603,7 +1603,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp if (vartok->previous()->str() == "return") return true; - // Passing variable to typeof + // Passing variable to typeof/__alignof__ if (Token::Match(vartok->tokAt(-3), "typeof|__alignof__ ( * %var%")) return false;