Uninitialized variables; Fixed struct member access FP

This commit is contained in:
Daniel Marjamäki 2021-05-17 11:50:31 +02:00
parent c78a1dbbaf
commit 4322311482
2 changed files with 8 additions and 1 deletions

View File

@ -1023,7 +1023,7 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
while (Token::Match(valueExpr->astParent(), ".|::") && astIsRhs(valueExpr))
valueExpr = valueExpr->astParent();
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())
return nullptr;
while (Token::simpleMatch(valueExpr->astParent(), ".") && astIsLhs(valueExpr) && valueExpr->astParent()->valueType() && valueExpr->astParent()->valueType()->pointer == 0)
valueExpr = valueExpr->astParent();

View File

@ -3590,6 +3590,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(void) {\n"
" struct tm t;\n"
" t.tm_year = 123;\n"
"}");
ASSERT_EQUALS("", errout.str());
// return
checkUninitVar("struct AB { int a; int b; };\n"
"void f(void) {\n"
@ -4279,6 +4285,7 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// struct
valueFlowUninit("struct AB { int a; int b; };\n"
"void f(void) {\n"
" AB ab;\n"