Fix #11597 FP uninitvar with nested enum (#4847)

This commit is contained in:
chrchr-github 2023-03-04 11:57:12 +01:00 committed by GitHub
parent 350a1f2dfc
commit b4c90f8b2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -1620,7 +1620,7 @@ void CheckUninitVar::valueFlowUninit()
continue; continue;
uninitderef = deref && v->indirect == 0; uninitderef = deref && v->indirect == 0;
const bool isleaf = isLeafDot(tok) || uninitderef; const bool isleaf = isLeafDot(tok) || uninitderef;
if (Token::Match(tok->astParent(), ". %var%") && !isleaf) if (!isleaf && Token::Match(tok->astParent(), ". %name%") && (tok->astParent()->next()->varId() || tok->astParent()->next()->isEnumerator()))
continue; continue;
} }
const ExprUsage usage = getExprUsage(tok, v->indirect, mSettings); const ExprUsage usage = getExprUsage(tok, v->indirect, mSettings);

View File

@ -6272,6 +6272,16 @@ private:
" h.e();\n" " h.e();\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #11597
valueFlowUninit("void f(size_t f) {\n"
" struct {\n"
" int i;\n"
" enum { offset = 1062 };\n"
" } s;\n"
" if (f < s.offset + sizeof(s)) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void uninitvar_memberfunction() { void uninitvar_memberfunction() {