-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix miscellaneous static analyzer warnings #7670
Conversation
Fixed static analyzer warnings in MGLNetworkConfiguration, MGLRasterSource, and MGLShape.
Fixed static analyzer warnings in MGLAnnotationImage.
Fixed static analyzer warnings in MGLAnnotationImage and NSImage(MGLAdditions).
@@ -12,9 +11,6 @@ + (void)load { | |||
} | |||
|
|||
+ (instancetype)sharedManager { | |||
if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+[MGLAccountManager sharedManager]
bails in IB because MGLAccountManager spins up lots of other machinery, including MGLMapboxEvents. MGLNetworkConfiguration is intentionally isolated from anything else, so initializing the singleton within IB is no big deal.
@@ -57,15 +57,11 @@ - (BOOL)isEqual:(id)other { | |||
|
|||
return ((!_reuseIdentifier && !otherAnnotationImage.reuseIdentifier) || [_reuseIdentifier isEqualToString:otherAnnotationImage.reuseIdentifier]) | |||
&& _enabled == otherAnnotationImage.enabled | |||
&& ((!_image && !otherAnnotationImage.image) || [UIImagePNGRepresentation(_image) isEqualToData:UIImagePNGRepresentation(otherAnnotationImage.image)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frederoni, any reason why comparing two UIImages for object equality isn’t good enough? (There’s a similar comparison of NSImages’ TIFF representations on the macOS side.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that testAnnotationImage()
is failing as a result of my change. It’s true that drawing the image to a new context could make the two images unequal, but there are a number of reasons that would be the case anyways (such as different color profiles). In general, I don’t think a class’s -isEqual:
implementation should be more thorough than the -isEqual:
implementations of its ivars.
Edit: I misread the test. Looks like it’s doing something pretty ordinary.
@@ -51,7 +51,7 @@ - (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NS_A | |||
if (self = [super initWithIdentifier:identifier tileURLTemplates:tileURLTemplates options:options]) { | |||
mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, options); | |||
|
|||
uint16_t tileSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had somehow forgotten that primitive-typed stack variables are uninitialized in Objective-C just as they are in C. ARC nils out only object pointers on the stack.
NSUInteger hash; | ||
hash += _title.hash; | ||
hash += _subtitle.hash; | ||
NSUInteger hash = _title.hash + _subtitle.hash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a safe way to compute the hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A XOR over the values could improve it but I'm ok with it because this is an abstract class and can't be used directly. All concrete subclasses include the hash of the GeoJSON dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fairly conventional implementation, as far as I know. The only hard requirement for a -hash
implementation is that two equal objects (as in -isEqual:
) must have the same hash. But feel free to improve on the various -hash
implementations in this SDK in a separate PR.
This PR fixes the following static analyzer warnings, which were introduced in #6709, #7377, #6559, and #7300:
Working towards #7668.
/cc @frederoni @incanus