From e6122d9bf0d4b38059ee125fcfcfe7b369907a40 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Apr 2017 11:51:40 -0700 Subject: [PATCH] [darwin] Preflight argument validity before constructing mbgl::LatLng --- platform/darwin/src/MGLGeometry_Private.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h index e6b37b353..ac0ff485a 100644 --- a/platform/darwin/src/MGLGeometry_Private.h +++ b/platform/darwin/src/MGLGeometry_Private.h @@ -13,6 +13,18 @@ CGRect MGLExtendRect(CGRect rect, CGPoint point); NS_INLINE mbgl::LatLng MGLLatLngFromLocationCoordinate2D(CLLocationCoordinate2D coordinate) { + if (std::isnan(coordinate.latitude)) { + [NSException raise:NSInvalidArgumentException format:@"latitude must not be NaN"]; + } + if (std::isnan(coordinate.longitude)) { + [NSException raise:NSInvalidArgumentException format:@"longitude must not be NaN"]; + } + if (std::abs(coordinate.latitude) > 90.0) { + [NSException raise:NSInvalidArgumentException format:@"latitude must be between -90 and 90"]; + } + if (!std::isfinite(coordinate.longitude)) { + [NSException raise:NSInvalidArgumentException format:@"longitude must not be infinite"]; + } return mbgl::LatLng(coordinate.latitude, coordinate.longitude); }