From b3c2ea2c4f7904c6d86e9a4141d0d55db48d2b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Jan 2015 11:13:20 +0100 Subject: [PATCH] CheckUninitVar: Fix fp for 'int x=2+x();' when x() is an unseen preprocessor macro --- lib/checkuninitvar.cpp | 4 ++++ test/testuninitvar.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ff41b22ce..18cf8ff99 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1751,6 +1751,10 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all if (vartok->previous()->str() == "&" && !vartok->previous()->astOperand2()) return false; + // bailout to avoid fp for 'int x = 2 + x();' where 'x()' is a unseen preprocessor macro (seen in linux) + if (!pointer && vartok->next() && vartok->next()->str() == "(") + return false; + if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) { if (alloc && vartok->previous()->str() == "*") { const Token *parent = vartok->previous()->astParent(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b72660062..b79026909 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1934,6 +1934,11 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); + checkUninitVar2("void foo() {\n" + " int f = 1 + f();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // calling noreturn function.. checkUninitVar("int foo(int a) {\n" " int x;\n"