summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-04-30 17:08:37 -0400
committerGitHub <noreply@github.com>2019-04-30 17:08:37 -0400
commit9bd59bf041b0d0ca400f586fdbfed53d06258613 (patch)
tree03306eb75f839c993c4c4c2881f7381e9329c03f
parentb15b78346fe44afbdb81934606ab63252df96b66 (diff)
downloadqtlocation-mapboxgl-9bd59bf041b0d0ca400f586fdbfed53d06258613.tar.gz
[ios, macos] Fixes for static analyzer warnings (#14453)
-rw-r--r--platform/darwin/src/MGLStyleValue_Private.h2
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.h2
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm17
-rw-r--r--platform/darwin/src/NSExpression+MGLPrivateAdditions.h4
-rw-r--r--platform/darwin/src/NSPredicate+MGLPrivateAdditions.h6
-rw-r--r--platform/ios/app/MBXCustomLocationViewController.m1
-rw-r--r--platform/ios/app/MBXFrameTimeGraphView.m7
-rw-r--r--platform/ios/app/MBXOrnamentsViewController.m2
-rw-r--r--platform/ios/app/MBXViewController.m16
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj12
-rw-r--r--platform/ios/src/MGLMapView.h8
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/ios/src/UIView+MGLAdditions.h2
-rwxr-xr-xplatform/ios/vendor/SMCalloutView/SMCalloutView.m9
14 files changed, 62 insertions, 28 deletions
diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h
index fee34b4b71..376bf5e73b 100644
--- a/platform/darwin/src/MGLStyleValue_Private.h
+++ b/platform/darwin/src/MGLStyleValue_Private.h
@@ -291,7 +291,7 @@ private: // Private utilities for converting from mbgl to mgl values
}
// Array
- static ObjCType toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) {
+ static NSArray<NSExpression*> *toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:mbglStopValue.size()];
for (const auto &mbglElement: mbglStopValue) {
[array addObject:[NSExpression expressionForConstantValue:toMGLRawStyleValue(mbglElement)]];
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h
index a19ec1af2e..9ef6623068 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.h
+++ b/platform/darwin/src/NSExpression+MGLAdditions.h
@@ -190,7 +190,7 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionI
@return An initialized expression equivalent to `object`, suitable for use as
the value of a style layer attribute.
*/
-+ (instancetype)expressionWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:));
++ (instancetype)expressionWithMGLJSONObject:(nullable id)object NS_SWIFT_NAME(init(mglJSONObject:));
/**
An equivalent Foundation object that can be serialized as JSON.
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 9dad00e56e..026d8bec02 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -823,9 +823,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
minimum = [NSExpression expressionWithMGLJSONObject:valueExpression];
}
}
- NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
- return [NSExpression expressionForFunction:@"mgl_step:from:stops:"
- arguments:@[inputExpression, minimum, stopExpression]];
+
+ NSAssert(minimum, @"minimum should be non-nil");
+ if (minimum) {
+ NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops];
+ return [NSExpression expressionForFunction:@"mgl_step:from:stops:"
+ arguments:@[inputExpression, minimum, stopExpression]];
+ }
+
} else if ([op isEqualToString:@"zoom"]) {
return NSExpression.zoomLevelVariableExpression;
} else if ([op isEqualToString:@"heatmap-density"]) {
@@ -1030,7 +1035,11 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
expressionObject = @[@"get", pathComponent];
}
}
- return expressionObject;
+
+ NSAssert(expressionObject.count > 0, @"expressionObject should be non-empty");
+
+ // Return a non-null value to quieten static analysis
+ return expressionObject ?: @[];
}
case NSFunctionExpressionType: {
diff --git a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
index 4ef49a2d15..54bc9068f4 100644
--- a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
+++ b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h
@@ -13,8 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface NSObject (MGLExpressionAdditions)
-- (NSNumber *)mgl_number;
-- (NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION;
+- (nullable NSNumber *)mgl_number;
+- (nullable NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION;
@end
diff --git a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
index 1828009678..051a2775a1 100644
--- a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
+++ b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h
@@ -10,15 +10,15 @@ NS_ASSUME_NONNULL_BEGIN
- (mbgl::style::Filter)mgl_filter;
-+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
++ (nullable instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter;
@end
@interface NSPredicate (MGLExpressionAdditions)
-- (id)mgl_if:(id)firstValue, ...;
+- (nullable id)mgl_if:(id)firstValue, ...;
-- (id)mgl_match:(NSExpression *)firstCase, ...;
+- (nullable id)mgl_match:(NSExpression *)firstCase, ...;
@end
diff --git a/platform/ios/app/MBXCustomLocationViewController.m b/platform/ios/app/MBXCustomLocationViewController.m
index 34887c5736..0473f8c2ef 100644
--- a/platform/ios/app/MBXCustomLocationViewController.m
+++ b/platform/ios/app/MBXCustomLocationViewController.m
@@ -168,6 +168,7 @@
}
- (void)viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
self.mapView.showsUserLocation = NO;
}
diff --git a/platform/ios/app/MBXFrameTimeGraphView.m b/platform/ios/app/MBXFrameTimeGraphView.m
index f689768818..e881eb9f48 100644
--- a/platform/ios/app/MBXFrameTimeGraphView.m
+++ b/platform/ios/app/MBXFrameTimeGraphView.m
@@ -59,7 +59,12 @@ const CGFloat MBXFrameTimeBarWidth = 4.f;
self.scrollLayer.frame = self.bounds;
CGRect thresholdLineRect = CGRectMake(0, self.frame.size.height - [self renderDurationTargetMilliseconds], self.frame.size.width, 1);
- self.thresholdLayer.path = CGPathCreateWithRect(thresholdLineRect, nil);
+
+ {
+ CGPathRef path = CGPathCreateWithRect(thresholdLineRect, nil);
+ self.thresholdLayer.path = path;
+ CGPathRelease(path);
+ }
}
}
diff --git a/platform/ios/app/MBXOrnamentsViewController.m b/platform/ios/app/MBXOrnamentsViewController.m
index 5c7aac7f88..861d5d7678 100644
--- a/platform/ios/app/MBXOrnamentsViewController.m
+++ b/platform/ios/app/MBXOrnamentsViewController.m
@@ -72,11 +72,13 @@
}
- (void)viewDidDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
[self.timer invalidate];
self.timer = nil;
}
- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(onTimerTick)
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 8d936d6a25..1bd2b2f5b3 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -155,13 +155,13 @@ CLLocationCoordinate2D randomWorldCoordinate() {
{{ 12.966246, 77.586505 }, 19000 } // Bengaluru
};
- NSInteger index = drand48() * (sizeof(landmasses)/sizeof(landmasses[0]));
+ NSInteger index = arc4random_uniform(sizeof(landmasses)/sizeof(landmasses[0]));
CLLocationCoordinate2D coordinate = landmasses[index].coordinate;
CLLocationDistance radius = landmasses[index].radius;
// Now create a world coord
- CLLocationDegrees heading = drand48()*360.0;
- CLLocationDistance distance = drand48()*radius;
+ CLLocationDegrees heading = (CLLocationDegrees)arc4random_uniform(360);
+ CLLocationDistance distance = (CLLocationDistance)arc4random_uniform(radius);
CLLocationCoordinate2D newLocation = coordinateCentered(coordinate, heading, distance);
return newLocation;
}
@@ -1775,8 +1775,8 @@ CLLocationCoordinate2D randomWorldCoordinate() {
NSMutableArray *annotations = [[NSMutableArray alloc] initWithCapacity:numAnnotations];
for (NSInteger i = 0; i<numAnnotations; i++) {
- CLLocationDegrees heading = drand48()*360.0;
- CLLocationDistance distance = drand48()*radius;
+ CLLocationDegrees heading = (CLLocationDegrees)arc4random_uniform(360);
+ CLLocationDistance distance = (CLLocationDistance)arc4random_uniform(radius);
CLLocationCoordinate2D newLocation = coordinateCentered(coordinate, heading, distance);
MBXDroppedPinAnnotation *annotation = [[MBXDroppedPinAnnotation alloc] init];
@@ -1814,12 +1814,12 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self.mapView addAnnotation:annotation];
// Add annotations around that coord
- [self addAnnotations:50 aroundCoordinate:annotation.coordinate radius:100000.0]; // 100km
+ [self addAnnotations:50 aroundCoordinate:annotation.coordinate radius:100000]; // 100km
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:annotation.coordinate
altitude:10000.0
- pitch:drand48()*60.0
- heading:drand48()*360];
+ pitch:(CLLocationDegrees)arc4random_uniform(60)
+ heading:(CLLocationDegrees)arc4random_uniform(360)];
[self.mapView flyToCamera:camera
withDuration:duration
peakAltitude:2000000.0
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 9a7a0dd100..dd5ca9abcd 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -3630,8 +3630,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_GCD_PERFORMANCE = YES;
+ CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -3899,8 +3903,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_GCD_PERFORMANCE = YES;
+ CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -3967,8 +3975,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_GCD_PERFORMANCE = YES;
+ CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h
index 607a197840..2423d62ee1 100644
--- a/platform/ios/src/MGLMapView.h
+++ b/platform/ios/src/MGLMapView.h
@@ -1130,7 +1130,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given coordinate bounds, with the specified camera,
@@ -1150,7 +1150,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given shape, with the specified camera,
@@ -1169,7 +1169,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets;
/**
Returns the camera that best fits the given shape, with the specified direction,
@@ -1187,7 +1187,7 @@ MGL_EXPORT
`UIApplicationWillTerminateNotification`; you may receive a `nil` return value
depending on the order of notification delivery.
*/
-- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets;
+- (nullable MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets;
/**
Returns the point in this view’s coordinate system on which to "anchor" in
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 345ac64bc7..b5383ee30e 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2481,7 +2481,7 @@ public:
}];
[attributionController addAction:telemetryAction];
- NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"");
+ NSString *cancelTitle = NSLocalizedStringWithDefaultValue(@"CANCEL", nil, nil, @"Cancel", @"Cancel");
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle
style:UIAlertActionStyleCancel
handler:NULL];
diff --git a/platform/ios/src/UIView+MGLAdditions.h b/platform/ios/src/UIView+MGLAdditions.h
index 85fea31ad2..ef074215b3 100644
--- a/platform/ios/src/UIView+MGLAdditions.h
+++ b/platform/ios/src/UIView+MGLAdditions.h
@@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface UIView (MGLAdditions)
-- (UIViewController *)mgl_viewControllerForLayoutGuides;
+- (nullable UIViewController *)mgl_viewControllerForLayoutGuides;
- (NSLayoutYAxisAnchor *)mgl_safeTopAnchor;
diff --git a/platform/ios/vendor/SMCalloutView/SMCalloutView.m b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
index 66a7b5a7a7..0520ba08a5 100755
--- a/platform/ios/vendor/SMCalloutView/SMCalloutView.m
+++ b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
@@ -554,13 +554,18 @@ NSTimeInterval const kMGLSMCalloutViewRepositionDelayForUIScrollView = 1.0/3.0;
stretch.toValue = presenting ? @1.0 : @0.0;
animation = stretch;
}
-
+
+ NSAssert(animation, @"There should be an animation");
+
// CAAnimation is KVC compliant, so we can store whether we're presenting for lookup in our delegate methods
[animation setValue:@(presenting) forKey:@"presenting"];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
- return animation;
+
+ // Cast as non-null to mute static analysis warning as documented at
+ // https://clang-analyzer.llvm.org/faq.html#decide_nullability
+ return (CAAnimation * _Nonnull)animation;
}
- (void)layoutSubviews {