Fixed #6769 (false positive: Uninitialized struct member: epoch.integer)

This commit is contained in:
Daniel Marjamäki 2015-11-22 16:20:46 +01:00
parent 63b7700660
commit d93cf96a29
2 changed files with 37 additions and 3 deletions

View File

@ -1050,7 +1050,12 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
return true;
} else if (tok->strAt(1) == "=")
return true;
else if (tok->strAt(-1) == "&") {
else if (Token::Match(tok, "%var% . %name% (")) {
const Token *ftok = tok->tokAt(2);
if (!ftok->function() || !ftok->function()->isConst())
// TODO: Try to determine if membervar is assigned in method
return true;
} else if (tok->strAt(-1) == "&") {
if (Token::Match(tok->tokAt(-2), "[(,] & %name%")) {
// locate start parentheses in function call..
unsigned int argumentNumber = 0;

View File

@ -3101,13 +3101,15 @@ private:
ASSERT_EQUALS("", errout.str());
{
checkUninitVar("void f(void) {\n"
checkUninitVar("struct AB { char a[10]; };\n"
"void f(void) {\n"
" struct AB ab;\n"
" strcpy(ab.a, STR);\n"
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(void) {\n"
checkUninitVar("struct AB { char a[10]; };\n"
"void f(void) {\n"
" struct AB ab;\n"
" strcpy(x, ab.a);\n"
"}\n", "test.c");
@ -3130,6 +3132,33 @@ private:
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
{
// #6769 - calling method that might assign struct members
checkUninitVar("struct AB { int a; int b; void set(); };\n"
"void f(void) {\n"
" struct AB ab;\n"
" ab.set();\n"
" x = ab;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("struct AB { int a; int get() const; };\n"
"void f(void) {\n"
" struct AB ab;\n"
" ab.get();\n"
" x = ab;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str());
checkUninitVar("struct AB { int a; void dostuff() {} };\n"
"void f(void) {\n"
" struct AB ab;\n"
" ab.dostuff();\n"
" x = ab;\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout.str());
}
checkUninitVar("struct AB { int a; struct { int b; int c; } s; };\n"
"void do_something(const struct AB ab);\n"
"void f(void) {\n"