Skip to content

Commit 923bf1f

Browse files
authored
Merge pull request #71664 from mikeash/build-metadata-demangling-null-checks
[Runtime] Add some missing NULL checks to _swift_buildDemanglingForMetadata calls.
2 parents dae46c3 + 8dc4bc1 commit 923bf1f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

stdlib/public/runtime/Demangle.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
530530
// If there is a superclass constraint, we mangle it specially.
531531
auto result = Dem.createNode(Node::Kind::ProtocolListWithClass);
532532
auto superclassNode = _swift_buildDemanglingForMetadata(superclass, Dem);
533+
if (!superclassNode)
534+
return nullptr;
533535

534536
result->addChild(proto_list, Dem);
535537
result->addChild(superclassNode, Dem);
@@ -573,6 +575,8 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
573575
auto metatype = static_cast<const ExistentialMetatypeMetadata *>(type);
574576
auto instance = _swift_buildDemanglingForMetadata(metatype->InstanceType,
575577
Dem);
578+
if (!instance)
579+
return nullptr;
576580
auto node = Dem.createNode(Node::Kind::ExistentialMetatype);
577581
node->addChild(instance, Dem);
578582
return node;
@@ -605,6 +609,11 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
605609
auto flags = func->getParameterFlags(i);
606610
auto input = _swift_buildDemanglingForMetadata(param, Dem);
607611

612+
// If we failed to build the demangling for an input, we have to fail
613+
// building the demangling for the function type too.
614+
if (!input)
615+
return nullptr;
616+
608617
auto wrapInput = [&](Node::Kind kind) {
609618
auto parent = Dem.createNode(kind);
610619
parent->addChild(input, Dem);
@@ -691,13 +700,18 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
691700

692701
NodePointer resultTy = _swift_buildDemanglingForMetadata(func->ResultType,
693702
Dem);
703+
if (!resultTy)
704+
return nullptr;
705+
694706
NodePointer result = Dem.createNode(Node::Kind::ReturnType);
695707
result->addChild(resultTy, Dem);
696708

697709
auto funcNode = Dem.createNode(kind);
698710
if (func->hasGlobalActor()) {
699711
auto globalActorTypeNode =
700712
_swift_buildDemanglingForMetadata(func->getGlobalActor(), Dem);
713+
if (!globalActorTypeNode)
714+
return nullptr;
701715
NodePointer globalActorNode =
702716
Dem.createNode(Node::Kind::GlobalActorFunctionType);
703717
globalActorNode->addChild(globalActorTypeNode, Dem);
@@ -731,6 +745,8 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
731745
if (auto thrownError = func->getThrownError()) {
732746
auto thrownErrorTypeNode =
733747
_swift_buildDemanglingForMetadata(thrownError, Dem);
748+
if (!thrownErrorTypeNode)
749+
return nullptr;
734750
NodePointer thrownErrorNode =
735751
Dem.createNode(Node::Kind::TypedThrowsAnnotation);
736752
thrownErrorNode->addChild(thrownErrorTypeNode, Dem);
@@ -790,6 +806,8 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
790806
// Add the element type child.
791807
auto eltType =
792808
_swift_buildDemanglingForMetadata(tuple->getElement(i).Type, Dem);
809+
if (!eltType)
810+
return nullptr;
793811

794812
if (eltType->getKind() == Node::Kind::Type) {
795813
elt->addChild(eltType, Dem);

0 commit comments

Comments
 (0)