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).
| } | ||
|
|
||
| + (instancetype)sharedManager { | ||
| if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { |
There was a problem hiding this comment.
+[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.
|
|
||
| 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.
@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.
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.
| 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.
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.
Is this a safe way to compute the hash?
There was a problem hiding this comment.
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.
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