Skip to content

Commit 9780246

Browse files
Merge pull request #71623 from adrian-prantl/122698966
Add missing checks for nullptr.
2 parents 60f9c03 + e901376 commit 9780246

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,26 @@ class MetadataReader {
527527
// Dig out the protocol from the protocol list.
528528
auto protocolList = readMangledName(resolved.getResolvedAddress(),
529529
MangledNameKind::Type, dem);
530-
assert(protocolList->getFirstChild()
531-
->getFirstChild()
532-
->getFirstChild()
533-
->getFirstChild()
534-
->getKind() == Node::Kind::Protocol);
535-
auto protocol = protocolList->getFirstChild()
536-
->getFirstChild()
537-
->getFirstChild()
538-
->getFirstChild();
530+
assert(protocolList && protocolList->getNumChildren());
531+
if (!protocolList || !protocolList->getNumChildren())
532+
return nullptr;
533+
auto child = protocolList->getFirstChild();
534+
assert(child && child->getNumChildren());
535+
if (!child || !child->getNumChildren())
536+
return nullptr;
537+
child = child->getFirstChild();
538+
assert(child && child->getNumChildren());
539+
if (!child || !child->getNumChildren())
540+
return nullptr;
541+
assert(child && child->getNumChildren());
542+
child = child->getFirstChild();
543+
if (!child || !child->getNumChildren())
544+
return nullptr;
545+
child = child->getFirstChild();
546+
assert(child && child->getKind() == Node::Kind::Protocol);
547+
if (!child || child->getKind() != Node::Kind::Protocol)
548+
return nullptr;
549+
auto protocol = child;
539550
auto protocolType = dem.createNode(Node::Kind::Type);
540551
protocolType->addChild(protocol, dem);
541552
return protocolType;

0 commit comments

Comments
 (0)