diff --git a/infer/src/bufferoverrun/bufferOverrunModels.ml b/infer/src/bufferoverrun/bufferOverrunModels.ml index 20372445d..c6f1cd704 100644 --- a/infer/src/bufferoverrun/bufferOverrunModels.ml +++ b/infer/src/bufferoverrun/bufferOverrunModels.ml @@ -1733,6 +1733,10 @@ module Call = struct &:: "allValues" <>$ capt_exp $--> create_copy_array ; +PatternMatch.ObjectiveC.implements "NSDictionary" &:: "keyEnumerator" <>$ capt_exp $--> NSCollection.iterator + ; +PatternMatch.ObjectiveC.implements "NSOrderedSet" + &:: "orderedSet" $$--> NSCollection.new_collection + ; +PatternMatch.ObjectiveC.implements "NSOrderedSet" + &:: "orderedSetWithArray:" $ capt_exp $--> id ; +PatternMatch.ObjectiveC.implements "NSOrderedSet" &:: "reverseObjectEnumerator" <>$ capt_exp $--> NSCollection.iterator ; +PatternMatch.ObjectiveC.implements "NSNumber" &:: "numberWithInt:" <>$ capt_exp $--> id diff --git a/infer/tests/codetoanalyze/objc/performance/NSOrderedSet.m b/infer/tests/codetoanalyze/objc/performance/NSOrderedSet.m index 8852eaeda..a71618197 100644 --- a/infer/tests/codetoanalyze/objc/performance/NSOrderedSet.m +++ b/infer/tests/codetoanalyze/objc/performance/NSOrderedSet.m @@ -10,3 +10,13 @@ void nsordered_set_iterate_linear(NSOrderedSet* ordered_set) { for (id item in ordered_set) { } } + +void nsordered_set_empty_constant() { + NSOrderedSet* ordered_set = [NSOrderedSet orderedSet]; + nsordered_set_iterate_linear(ordered_set); +} + +void nsordered_set_with_array_linear(NSArray* array) { + NSOrderedSet* ordered_set = [NSOrderedSet orderedSetWithArray:array]; + nsordered_set_iterate_linear(ordered_set); +} diff --git a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp index 4cd748049..031f0c714 100644 --- a/infer/tests/codetoanalyze/objc/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/objc/performance/cost-issues.exp @@ -62,7 +62,9 @@ codetoanalyze/objc/performance/NSMutableDictionary.m, nsmutabledictionary_set_el codetoanalyze/objc/performance/NSMutableString.m, copy_string_constant_FP, 11 + 3 ⋅ str3.length.ub + str3.length.ub + 3 ⋅ (str3.length.ub + 1), OnUIThread:false, [{str3.length.ub + 1},Loop,{str3.length.ub},Modeled call to NSMutableString.appendString:,{str3.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/NSOrderedSet.m, nsordered_set_empty_constant, 13, OnUIThread:false, [] codetoanalyze/objc/performance/NSOrderedSet.m, nsordered_set_iterate_linear, 5 + ordered_set->elements.length.ub + 4 ⋅ (ordered_set->elements.length.ub + 1), OnUIThread:false, [{ordered_set->elements.length.ub + 1},Loop,{ordered_set->elements.length.ub},Loop] +codetoanalyze/objc/performance/NSOrderedSet.m, nsordered_set_with_array_linear, 10 + array->elements.length.ub + 4 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Call to nsordered_set_iterate_linear,Loop,{array->elements.length.ub},Call to nsordered_set_iterate_linear,Loop] codetoanalyze/objc/performance/NSSet.m, nsset_enumerator_linear, 6 + 4 ⋅ set->elements.length.ub + 4 ⋅ (set->elements.length.ub + 1), OnUIThread:false, [{set->elements.length.ub + 1},Loop,{set->elements.length.ub},Loop] codetoanalyze/objc/performance/NSSet.m, nsset_init_constant, 9, OnUIThread:false, [] codetoanalyze/objc/performance/NSSet.m, nsset_init_with_array_linear, 7 + 3 ⋅ array->elements.length.ub + 3 ⋅ (array->elements.length.ub + 1), OnUIThread:false, [{array->elements.length.ub + 1},Loop,{array->elements.length.ub},Loop]