Uninitialized variables: Fixed false positives when pointer is dereferenced in unexpanded macro
This commit is contained in:
parent
9593e14d72
commit
f6b201bb3b
|
@ -1265,8 +1265,16 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
|
|||
}
|
||||
|
||||
bool unknown = false;
|
||||
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown))
|
||||
return true;
|
||||
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {
|
||||
// function parameter?
|
||||
bool functionParameter = false;
|
||||
if (Token::Match(vartok->tokAt(-2), "%var% (") || vartok->previous()->str() == ",")
|
||||
functionParameter = true;
|
||||
|
||||
// if this is not a function parameter report this dereference as variable usage
|
||||
if (!functionParameter)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Token::Match(vartok->next(), "++|--|%op%"))
|
||||
return true;
|
||||
|
|
|
@ -1972,6 +1972,12 @@ private:
|
|||
" if (100 == sizeof(i+1));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" struct ABC *abc;\n"
|
||||
" int i = ARRAY_SIZE(abc.a);"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue