Skip to content

Commit ad969c3

Browse files
authored
[Runtime] Fix a potential NULL pointer dereference. (#40956)
If we find multiple conformances for the same protocol, we generate a warning. This works fine for Swift types, but for Objective-C types it's possible that while generating the warning we might find that the type description is NULL. Fix by using swift_getTypeName(). rdar://86368350
1 parent c6fd6da commit ad969c3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,15 @@ swift_conformsToProtocolMaybeInstantiateSuperclasses(
981981
foundWitness = witness;
982982
foundType = searchType;
983983
} else {
984+
auto foundName = swift_getTypeName(foundType, true);
985+
auto searchName = swift_getTypeName(searchType, true);
984986
swift::warning(RuntimeErrorFlagNone,
985-
"Warning: '%s' conforms to protocol '%s', but it also "
986-
"inherits conformance from '%s'. Relying on a "
987+
"Warning: '%.*s' conforms to protocol '%s', but it also "
988+
"inherits conformance from '%.*s'. Relying on a "
987989
"particular conformance is undefined behaviour.\n",
988-
foundType->getDescription()->Name.get(),
990+
(int)foundName.length, foundName.data,
989991
protocol->Name.get(),
990-
searchType->getDescription()->Name.get());
992+
(int)searchName.length, searchName.data);
991993
}
992994
}
993995
}

test/multifile/protocol-conformance-redundant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// REQUIRES: executable_test
99
// XFAIL: windows
1010

11-
// CHECK: Warning: 'Sub' conforms to protocol 'Hello', but it also inherits conformance from 'Super'. Relying on a particular conformance is undefined behaviour.
11+
// CHECK: Warning: 'main.Sub' conforms to protocol 'Hello', but it also inherits conformance from 'Def.Super'. Relying on a particular conformance is undefined behaviour.
1212
// CHECK: Hello
1313

1414
import StdlibUnittest

0 commit comments

Comments
 (0)