Uninitialized variables: Fixed false positives when pointer is dereferenced in unexpanded macro

This commit is contained in:
Daniel Marjamäki 2011-12-27 10:18:49 +01:00
parent 9593e14d72
commit f6b201bb3b
2 changed files with 16 additions and 2 deletions

View File

@ -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;

View File

@ -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());
}
};