Uninitialized variables; Fixed false positive in member assignment

This commit is contained in:
Daniel Marjamäki 2021-05-17 10:31:02 +02:00
parent 16ce0f1dbf
commit b115e4a932
2 changed files with 10 additions and 0 deletions

View File

@ -1020,6 +1020,8 @@ static bool isVoidCast(const Token *tok)
const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const
{ {
const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable
while (Token::Match(valueExpr->astParent(), ".|::") && astIsRhs(valueExpr))
valueExpr = valueExpr->astParent();
if (!pointer) { if (!pointer) {
if (Token::Match(vartok, "%name% [.(]") && vartok->variable() && !vartok->variable()->isPointer() && vartok->variable()->isClass()) if (Token::Match(vartok, "%name% [.(]") && vartok->variable() && !vartok->variable()->isPointer() && vartok->variable()->isClass())
return nullptr; return nullptr;

View File

@ -4279,6 +4279,14 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct AB { int a; int b; };\n"
"void f(void) {\n"
" AB ab;\n"
" AB *p = &ab;\n"
" p->a = 1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Unknown types // Unknown types
{ {
valueFlowUninit("void a()\n" valueFlowUninit("void a()\n"