Uninitialized variables: Assume that function initializes struct if it is unknown if it does

This commit is contained in:
Daniel Marjamäki 2013-04-10 20:04:32 +02:00
parent 994c429b7d
commit 96a5429cee
2 changed files with 12 additions and 0 deletions

View File

@ -1397,6 +1397,9 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
if (isMemberVariableUsage(tok, var.isPointer(), membervar))
uninitStructMemberError(tok, tok->str() + "." + membervar);
else if (Token::Match(tok->previous(), "[(,] %var% [,)]"))
return true;
} else {
// Use variable
if (!suppressErrors && isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))

View File

@ -2506,6 +2506,15 @@ private:
" a(&c);\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("struct ABC { int a; };\n" // struct initialization
"void clear(struct ABC &abc);\n"
"int f() {\n"
" struct ABC abc;\n"
" clear(abc);\n"
" return abc.a;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void uninitvar2_value() {