diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 6cdb4c111..4bb9d9f76 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1497,10 +1497,8 @@ void CheckUninitVar::valueFlowUninit() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); // check every executable scope - for (const Scope &scope : symbolDatabase->scopeList) { - if (!scope.isExecutable()) - continue; - for (const Token* tok = scope.bodyStart; tok != scope.bodyEnd; tok = tok->next()) { + for (const Scope *scope : symbolDatabase->functionScopes) { + for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { if (isSizeOfEtc(tok)) { tok = tok->linkAt(1); continue; @@ -1528,9 +1526,11 @@ void CheckUninitVar::valueFlowUninit() bool unknown; const bool isarray = !tok->variable() || tok->variable()->isArray(); const bool ispointer = astIsPointer(tok) && !isarray; - const bool deref = ispointer && CheckNullPointer::isPointerDeRef(tok, unknown, mSettings); - if (v->indirect == 1 && !deref) + const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, mSettings); + if (ispointer && v->indirect == 1 && !deref) continue; + if (isarray && !deref) + continue; uninitderef = deref && v->indirect == 0; const bool isleaf = isLeafDot(tok) || uninitderef; if (Token::Match(tok->astParent(), ". %var%") && !isleaf) @@ -1541,7 +1541,7 @@ void CheckUninitVar::valueFlowUninit() continue; uninitvarError(tok, tok->expressionString(), v->errorPath); const Token* nextTok = nextAfterAstRightmostLeaf(parent); - if (nextTok == scope.bodyEnd) + if (nextTok == scope->bodyEnd) break; tok = nextTok ? nextTok : tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 7fd5ad450..aeba58373 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4769,6 +4769,15 @@ private: "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: flags\n", errout.str()); + valueFlowUninit("void foo() {\n" // #10293 + " union {\n" + " struct hdr cm;\n" + " char control[123];\n" + " } u;\n" + " char *x = u.control;\n" // <- no error + "}"); + ASSERT_EQUALS("", errout.str()); + valueFlowUninit("struct pc_data {\n" " struct {\n" " char * strefa;\n"