diff --git a/infer/src/bufferoverrun/bufferOverrunModels.ml b/infer/src/bufferoverrun/bufferOverrunModels.ml index f1a5934e7..9be12e3ab 100644 --- a/infer/src/bufferoverrun/bufferOverrunModels.ml +++ b/infer/src/bufferoverrun/bufferOverrunModels.ml @@ -1703,6 +1703,10 @@ module Call = struct &:: "allKeys" <>$ capt_exp $--> create_copy_array ; +PatternMatch.ObjectiveC.implements "NSDictionary" &:: "allValues" <>$ capt_exp $--> create_copy_array + ; +PatternMatch.ObjectiveC.implements "NSDictionary" + &:: "objectEnumerator" <>$ capt_exp $--> NSCollection.iterator + ; +PatternMatch.ObjectiveC.implements "NSDictionary" + &:: "keyEnumerator" <>$ capt_exp $--> NSCollection.iterator ; +PatternMatch.ObjectiveC.implements "NSNumber" &:: "numberWithInt:" <>$ capt_exp $--> id ; +PatternMatch.ObjectiveC.implements "NSNumber" &:: "integerValue" <>$ capt_exp $--> id ; +PatternMatch.ObjectiveC.implements "NSString" diff --git a/infer/tests/codetoanalyze/objc/performance/NSDictionary.m b/infer/tests/codetoanalyze/objc/performance/NSDictionary.m index 7da86c1f5..e29d2040e 100644 --- a/infer/tests/codetoanalyze/objc/performance/NSDictionary.m +++ b/infer/tests/codetoanalyze/objc/performance/NSDictionary.m @@ -67,7 +67,7 @@ void nsdictionary_all_values_linear(NSDictionary* dict) { } } -id nsdictionary_find_key_linear_FN(NSDictionary* dict, id item) { +id nsdictionary_find_key_constant(NSDictionary* dict, id item) { NSEnumerator* enumerator = [dict keyEnumerator]; id key; while ((key = [enumerator nextObject]) && dict[key] == item) { @@ -78,7 +78,7 @@ id nsdictionary_find_key_linear_FN(NSDictionary* dict, id item) { // enumerate dictionary -void nsdictionary_fast_enumerate_linear_FN(NSDictionary* dict) { +void nsdictionary_fast_enumerate_linear(NSDictionary* dict) { for (id key in dict) { } } @@ -93,7 +93,7 @@ void nsdictionary_enumerate_constant() { } } -void nsdictionary_enumerator_linear_FN(NSDictionary* dict) { +void nsdictionary_enumerator_linear(NSDictionary* dict) { NSEnumerator* enumerator = [dict keyEnumerator]; id key; while ((key = [enumerator nextObject])) { diff --git a/infer/tests/codetoanalyze/objc/performance/NSMutableDictionary.m b/infer/tests/codetoanalyze/objc/performance/NSMutableDictionary.m index 377b718d5..7b3469761 100644 --- a/infer/tests/codetoanalyze/objc/performance/NSMutableDictionary.m +++ b/infer/tests/codetoanalyze/objc/performance/NSMutableDictionary.m @@ -7,8 +7,7 @@ #import // set element -void nsmutabledictionary_set_element_in_loop_linear_FN( - NSMutableDictionary* dict) { +void nsmutabledictionary_set_element_in_loop_linear(NSMutableDictionary* dict) { for (NSString* key in dict) { dict[key] = key; } diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index 3b26b3b82..e7ae9a9f3 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -30,9 +30,9 @@ codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear2, 6 codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_values_linear, 3 + 3 ⋅ dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_dictionary_with_objects_linear, 14 + 15 ⋅ n_entries + 3 ⋅ n_entries + 2 ⋅ (1+max(0, n_entries)) + 4 ⋅ (1+max(0, n_entries)), OnUIThread:false, [{1+max(0, n_entries)},Loop,{1+max(0, n_entries)},Loop,{n_entries},Loop,{n_entries},Loop] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_constant, 52, OnUIThread:false, [] -codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerator_linear_FN, 10, OnUIThread:false, [] -codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_fast_enumerate_linear_FN, 10, OnUIThread:false, [] -codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_find_key_linear_FN, 19, OnUIThread:false, [] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerator_linear, 5 + dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_fast_enumerate_linear, 5 + dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] +codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_find_key_constant, 19, OnUIThread:false, [] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_dictionary_constant, 3, OnUIThread:false, [] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_literal_constant, 41, OnUIThread:false, [] codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, ⊤, OnUIThread:false, [Unbounded loop,Loop] @@ -51,7 +51,7 @@ codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_remove_constant, 17, codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_remove_in_loop_constant, 182, OnUIThread:false, [] codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_set_in_loop_constant, 51, OnUIThread:false, [] codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_set_linear, 3 + 11 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop] -codetoanalyze/objc/performance/NSMutableDictionary.m, nsmutabledictionary_set_element_in_loop_linear_FN, 14, OnUIThread:false, [] +codetoanalyze/objc/performance/NSMutableDictionary.m, nsmutabledictionary_set_element_in_loop_linear, 5 + 5 ⋅ dict->elements.length.ub + 4 ⋅ (dict->elements.length.ub + 1), OnUIThread:false, [{dict->elements.length.ub + 1},Loop,{dict->elements.length.ub},Loop] codetoanalyze/objc/performance/NSMutableString.m, nsmstring_append_string_constant, 14 + 3 ⋅ (str.length.ub + 5) + 3 ⋅ (str.length.ub + 6), OnUIThread:false, [{str.length.ub + 6},Loop,{str.length.ub + 5},Loop] codetoanalyze/objc/performance/NSMutableString.m, nsmstring_append_string_linear, 5 + str2.length.ub + 3 ⋅ (str2.length.ub + str1.length.ub) + 3 ⋅ (str2.length.ub + str1.length.ub + 1), OnUIThread:false, [{str2.length.ub + str1.length.ub + 1},Loop,{str2.length.ub + str1.length.ub},Loop,{str2.length.ub},Modeled call to NSMutableString.appendString:] codetoanalyze/objc/performance/NSString.m, call_component_separated_by_char_constant, 46, OnUIThread:false, []