CheckUninitVar: Fix fp for 'int x=2+x();' when x() is an unseen preprocessor macro
This commit is contained in:
parent
22bd20c94a
commit
b3c2ea2c4f
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue