Uninitialized member variable: Fixed false negative when struct is read
This commit is contained in:
parent
4c344adcf1
commit
8cc1f664d8
|
@ -1872,6 +1872,9 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
|
||||||
if (Token::Match(argStart, "const struct| %type% * const| %var% [,)]"))
|
if (Token::Match(argStart, "const struct| %type% * const| %var% [,)]"))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (Token::Match(ftok ? ftok->previous() : nullptr, "= * ("))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1891,6 +1894,14 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, boo
|
||||||
else if (!isPointer && Token::Match(tok->previous(), "= %var% ;"))
|
else if (!isPointer && Token::Match(tok->previous(), "= %var% ;"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// = *(&var);
|
||||||
|
else if (!isPointer &&
|
||||||
|
Token::simpleMatch(tok->astParent(),"&") &&
|
||||||
|
Token::simpleMatch(tok->astParent()->astParent(),"*") &&
|
||||||
|
Token::Match(tok->astParent()->astParent()->astParent(), "= * (| &") &&
|
||||||
|
tok->astParent()->astParent()->astParent()->astOperand2() == tok->astParent()->astParent())
|
||||||
|
return true;
|
||||||
|
|
||||||
else if (_settings->experimental &&
|
else if (_settings->experimental &&
|
||||||
!isPointer &&
|
!isPointer &&
|
||||||
Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]") &&
|
Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]") &&
|
||||||
|
|
|
@ -2917,6 +2917,14 @@ private:
|
||||||
"}\n", "test.c");
|
"}\n", "test.c");
|
||||||
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
|
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\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"
|
||||||
|
|
Loading…
Reference in New Issue