From 5156ff7f65922e5cd4467f1dc8037ae89062fad2 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Thu, 21 Jun 2018 03:15:22 -0700 Subject: [PATCH] [infer][PR] handle improper version strings in @available clauses Summary: Closes https://github.com/facebook/infer/pull/947 Reviewed By: dulmarod Differential Revision: D8531636 Pulled By: martintrojer fbshipit-source-id: 997d29c --- infer/src/base/Utils.ml | 2 +- .../tests/codetoanalyze/objc/ioslints/issues.exp | 12 ++++++------ .../objc/ioslints/unavailable_api_allowed_cases.m | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index 2d501f08d..7e609daa4 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -292,7 +292,7 @@ let suppress_stderr2 f2 x1 x2 = let compare_versions v1 v2 = let int_list_of_version v = - let lv = String.split ~on:'.' v in + let lv = match String.split ~on:'.' v with [v] -> [v; "0"] | v -> v in let int_of_string_or_zero v = try int_of_string v with Failure _ -> 0 in List.map ~f:int_of_string_or_zero lv in diff --git a/infer/tests/codetoanalyze/objc/ioslints/issues.exp b/infer/tests/codetoanalyze/objc/ioslints/issues.exp index ae22cf6dd..58be5c9d5 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/issues.exp +++ b/infer/tests/codetoanalyze/objc/ioslints/issues.exp @@ -1,9 +1,9 @@ -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m2, 134, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m3, 142, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_uifont_without_respondstoselector, 116, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else, 69, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_instances_responds_to_selector, 93, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector, 62, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m2, 137, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m3, 145, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_uifont_without_respondstoselector, 119, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else, 72, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_instances_responds_to_selector, 96, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector, 65, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 75, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test, 27, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_unsupported_class, 41, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] diff --git a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m index 9e545b067..93d59661d 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m +++ b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m @@ -4,8 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -#import #import +#import +#import +#import +#import @interface Unavailable_api_allowed_cases : NSObject @@ -206,4 +209,14 @@ } } +// no bug +- (PHAsset*)improper_ios_version_good:(NSDictionary*)info { + PHAsset* videoAsset = NULL; + if (@available(iOS 11, *)) { // not strictly correct version number, should be + // "11.0" We should handle this case anyway. + videoAsset = [info objectForKey:UIImagePickerControllerPHAsset]; + } + return videoAsset; +} + @end