Fixed #4760 (false negative: (error) usage of uninitialized variable (struct member))

This commit is contained in:
Daniel Marjamäki 2013-05-02 20:34:15 +02:00
parent 957e0790c6
commit bfb1bc50e3
2 changed files with 9 additions and 0 deletions

View File

@ -1616,6 +1616,8 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
return true; return true;
else if ((tok->previous() && tok->previous()->isConstOp()) || Token::Match(tok->previous(), "[|=")) else if ((tok->previous() && tok->previous()->isConstOp()) || Token::Match(tok->previous(), "[|="))
; // member variable usage ; // member variable usage
else if (tok->tokAt(3)->isConstOp())
; // member variable usage
else else
return true; return true;
} else if (tok->strAt(1) == "=") } else if (tok->strAt(1) == "=")

View File

@ -2713,6 +2713,13 @@ private:
"}\n", "test.c"); "}\n", "test.c");
ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str()); ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str());
checkUninitVar2("struct Fred { int a; };\n"
"void f() {\n"
" struct Fred fred;\n"
" if (fred.a==1) {}\n"
"}", "test.c");
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: fred.a\n", errout.str());
checkUninitVar2("struct S { int n; int m; };\n" checkUninitVar2("struct S { int n; int m; };\n"
"void f(void) {\n" "void f(void) {\n"
" struct S s;\n" " struct S s;\n"