Просмотр исходного кода

Add some objc runtime nullability safeguards

Tanner Bennett лет назад: 6
Родитель
Сommit
ec2b73ceda

+ 6 - 2
Classes/GlobalStateExplorers/RuntimeBrowser/DataSources/TBRuntimeController.m

@@ -76,8 +76,12 @@ static TBRuntimeController *controller = nil;
 }
 
 + (NSString *)shortBundleNameForClass:(NSString *)name {
-    NSString *imagePath = @(class_getImageName(NSClassFromString(name)));
-    return [[TBRuntime runtime] shortNameForImageName:imagePath];
+    const char *imageName = class_getImageName(NSClassFromString(name));
+    if (!imageName) {
+        return @"(unspecified)";
+    }
+    
+    return [[TBRuntime runtime] shortNameForImageName:@(imageName)];
 }
 
 + (NSString *)imagePathWithShortName:(NSString *)suffix {

+ 1 - 1
Classes/ObjectExplorers/FLEXObjectExplorer.m

@@ -142,7 +142,7 @@
         ]];
         [_allImageNames addObject:[FLEXStaticMetadata
             style:FLEXStaticMetadataRowStyleDefault
-            title:@"Image Name" string:@(class_getImageName(cls))
+            title:@"Image Name" string:@(class_getImageName(cls) ?: "Created at Runtime")
         ]];
     }
     

+ 1 - 1
Classes/Utility/Runtime/FLEXRuntimeUtility.m

@@ -623,7 +623,7 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
 #pragma mark - Metadata Helpers
 
 + (NSDictionary<NSString *, NSString *> *)attributesForProperty:(objc_property_t)property {
-    NSString *attributes = @(property_getAttributes(property));
+    NSString *attributes = @(property_getAttributes(property) ?: "");
     // Thanks to MAObjcRuntime for inspiration here.
     NSArray<NSString *> *attributePairs = [attributes componentsSeparatedByString:@","];
     NSMutableDictionary<NSString *, NSString *> *attributesDictionary = [NSMutableDictionary new];

+ 1 - 1
Classes/Utility/Runtime/Objc/FLEXIvar.m

@@ -67,7 +67,7 @@
 }
 
 - (void)examine {
-    _name         = @(ivar_getName(self.objc_ivar));
+    _name         = @(ivar_getName(self.objc_ivar) ?: "(nil)");
     _offset       = ivar_getOffset(self.objc_ivar);
     _typeEncoding = @(ivar_getTypeEncoding(self.objc_ivar) ?: "");
     

+ 1 - 1
Classes/Utility/Runtime/Objc/FLEXMethod.m

@@ -66,7 +66,7 @@
     if (self) {
         _objc_method = method;
         _isInstanceMethod = isInstanceMethod;
-        _signatureString = @(method_getTypeEncoding(method));
+        _signatureString = @(method_getTypeEncoding(method) ?: "?@:");
         
         NSString *cleanSig = nil;
         if ([FLEXTypeEncodingParser methodTypeEncodingSupported:_signatureString cleaned:&cleanSig]) {

+ 1 - 1
Classes/Utility/Runtime/Objc/FLEXProperty.m

@@ -59,7 +59,7 @@
     if (self) {
         _objc_property = property;
         _attributes    = [FLEXPropertyAttributes attributesForProperty:property];
-        _name          = @(property_getName(property));
+        _name          = @(property_getName(property) ?: "(nil)");
         _cls           = cls;
         
         if (!_attributes) [NSException raise:NSInternalInconsistencyException format:@"Error retrieving property attributes"];