Uninitialized struct member: fixed false negative when struct assignment is seen

This commit is contained in:
Daniel Marjamäki 2014-05-10 19:56:44 +02:00
parent b701f543c6
commit 4c344adcf1
2 changed files with 11 additions and 0 deletions

View File

@ -1888,6 +1888,9 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, boo
else if (!isPointer && Token::Match(tok->previous(), "[(,] %var% [,)]") && isVariableUsage(tok, isPointer, alloc, _tokenizer->isCPP())) else if (!isPointer && Token::Match(tok->previous(), "[(,] %var% [,)]") && isVariableUsage(tok, isPointer, alloc, _tokenizer->isCPP()))
return true; return true;
else if (!isPointer && Token::Match(tok->previous(), "= %var% ;"))
return true;
else if (_settings->experimental && else if (_settings->experimental &&
!isPointer && !isPointer &&
Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]") && Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]") &&

View File

@ -2909,6 +2909,14 @@ private:
"}\n", "test.c"); "}\n", "test.c");
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout.str()); ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout.str());
checkUninitVar2("struct AB { int a; int b; };\n"
"void f(void) {\n"
" struct AB ab;\n"
" ab.a = 1;\n"
" x = ab;\n"
"}\n", "test.c");
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
checkUninitVar2("struct AB { int a; int b; };\n" // pass struct member by address checkUninitVar2("struct AB { int a; int b; };\n" // pass struct member by address
"void f(void) {\n" "void f(void) {\n"
" struct AB ab;\n" " struct AB ab;\n"