Fix 10681: FP ctuuninitvar with array member (#3686)

This commit is contained in:
Paul Fultz II 2022-01-08 03:47:28 -06:00 committed by GitHub
parent 635c09643d
commit 0c9eb5d190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -6786,6 +6786,9 @@ static void valueFlowUninit(TokenList* tokenlist, SymbolDatabase* /*symbolDataba
for (const Variable& memVar : scope->varlist) {
if (!memVar.isPublic())
continue;
// Skip array since we cant track partial initialization from nested subexpressions
if (memVar.isArray())
continue;
if (!needsInitialization(&memVar, tokenlist->isCPP())) {
partial = true;
continue;

View File

@ -5921,6 +5921,35 @@ private:
" x = a.m;\n"
"}");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct S {\n"
" int t[1];\n"
"};\n"
"int f(const S* ps) {\n"
" return ps->t[0];\n"
"}\n"
"void g() {\n"
" S s;\n"
" s.t[0] = 1;\n"
" f(&s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct X {\n"
" int a, b;\n"
"};\n"
"struct S {\n"
" X t;\n"
"};\n"
"int f(const S* ps) {\n"
" return ps->t.a;\n"
"}\n"
"void g() {\n"
" S s;\n"
" s.t.a = 1;\n"
" f(&s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitvar_memberfunction() {