Uninitialized variables: Assume that function initializes struct if it is unknown if it does
This commit is contained in:
parent
994c429b7d
commit
96a5429cee
|
@ -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()))
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue