Uninitialized struct member: Fixed false negatives for return statements

This commit is contained in:
Daniel Marjamki 2013-01-20 17:54:32 +01:00
parent d33341a21a
commit 76534ccd1b
2 changed files with 10 additions and 3 deletions

View File

@ -1321,9 +1321,16 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
while (tok && tok->str() != ";") {
// variable is seen..
if (tok->varId() == var.varId() && (membervar.empty())) {
if (tok->varId() == var.varId()) {
if (!membervar.empty()) {
if (Token::Match(tok, "%var% . %var% ;|%op%") && tok->strAt(2) == membervar)
uninitStructMemberError(tok, tok->str() + "." + membervar);
else
return true;
}
// Use variable
if (!suppressErrors && isVariableUsage(scope, tok, var.isPointer()))
else if (!suppressErrors && isVariableUsage(scope, tok, var.isPointer()))
uninitvarError(tok, tok->str());
else

View File

@ -2635,7 +2635,7 @@ private:
" ab.a = 0;\n"
" return ab.b;\n"
"}\n", "test.c", true);
TODO_ASSERT_EQUALS("error", "", errout.str());
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
checkUninitVar2("struct AB { int a; int b; };\n"
"void f(void) {\n"