| 4573 | |
| 4574 | |
| 4575 | void CheckOtherImpl::checkUnionZeroInit() |
| 4576 | { |
| 4577 | if (!mSettings.severity.isEnabled(Severity::portability)) |
| 4578 | return; |
| 4579 | |
| 4580 | logChecker("CheckOther::checkUnionZeroInit"); // portability |
| 4581 | |
| 4582 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 4583 | |
| 4584 | std::unordered_map<const Scope *, Union> unionsByScopeId; |
| 4585 | const std::vector<Union> unions = parseUnions(*symbolDatabase, mSettings); |
| 4586 | for (const Union &u : unions) { |
| 4587 | unionsByScopeId.emplace(u.scope, u); |
| 4588 | } |
| 4589 | |
| 4590 | for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 4591 | if (!tok->isName() || !isZeroInitializer(tok->next())) |
| 4592 | continue; |
| 4593 | |
| 4594 | const ValueType *vt = tok->valueType(); |
| 4595 | if (vt == nullptr || vt->typeScope == nullptr) |
| 4596 | continue; |
| 4597 | auto it = unionsByScopeId.find(vt->typeScope); |
| 4598 | if (it == unionsByScopeId.end()) |
| 4599 | continue; |
| 4600 | const Union &u = it->second; |
| 4601 | if (!u.isLargestMemberFirst()) { |
| 4602 | const UnionMember *largestMember = u.largestMember(); |
| 4603 | if (largestMember == nullptr) { |
| 4604 | throw InternalError(tok, "Largest union member not found", |
| 4605 | InternalError::INTERNAL); |
| 4606 | } |
| 4607 | assert(largestMember != nullptr); |
| 4608 | unionZeroInitError(tok, *largestMember); |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | void CheckOtherImpl::unionZeroInitError(const Token *tok, |
| 4614 | const UnionMember& largestMember) |
no test coverage detected