Uninitialized struct member: Avoid false positive when struct member is passed by address
This commit is contained in:
parent
89b54cb2c9
commit
e63f2c3b5b
|
@ -1346,6 +1346,8 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
if (Token::Match(tok, "%var% . %var%") && tok->strAt(2) == membervar) {
|
if (Token::Match(tok, "%var% . %var%") && tok->strAt(2) == membervar) {
|
||||||
if (Token::Match(tok->tokAt(3), "[=.[]"))
|
if (Token::Match(tok->tokAt(3), "[=.[]"))
|
||||||
return true;
|
return true;
|
||||||
|
else if (Token::Match(tok->tokAt(-2), "[(,=] &"))
|
||||||
|
return true;
|
||||||
else if (Token::Match(tok->previous(), "%op%") || Token::Match(tok->previous(), "[|="))
|
else if (Token::Match(tok->previous(), "%op%") || Token::Match(tok->previous(), "[|="))
|
||||||
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
||||||
else
|
else
|
||||||
|
|
|
@ -2578,6 +2578,13 @@ private:
|
||||||
"}\n", "test.c", true);
|
"}\n", "test.c", true);
|
||||||
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" // pass struct member by address
|
||||||
|
"void f(void) {\n"
|
||||||
|
" struct AB ab;\n"
|
||||||
|
" assign(&ab.a, 0);\n"
|
||||||
|
"}\n", "test.c", true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar2("struct AB { int a; int b; };\n"
|
checkUninitVar2("struct AB { int a; int b; };\n"
|
||||||
"void do_something(const struct AB ab);\n"
|
"void do_something(const struct AB ab);\n"
|
||||||
"void f(void) {\n"
|
"void f(void) {\n"
|
||||||
|
|
Loading…
Reference in New Issue