diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index da4c83e0c..b2e0b07db 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -45,7 +45,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let is_objc_container_add_method : Typ.Procname.t -> bool = let method_prefixes = [ "arrayWithObjects:" - ; "arrayWithObjects:count:" + ; "arrayWithObjects:" + ; "arrayByAddingObject:" ; "dictionaryWithObjectsAndKeys:" ; "initWithObjectsAndKeys:" ; "dictionaryWithObjects:" ] @@ -262,4 +263,3 @@ let checker {Callbacks.summary; proc_desc; tenv} = let proc_data = ProcData.make proc_desc tenv summary in ignore (Analyzer.compute_post proc_data ~initial) ; summary - diff --git a/infer/tests/codetoanalyze/objc/checkers/Nullable.m b/infer/tests/codetoanalyze/objc/checkers/Nullable.m index c0d20c17c..0ca925fc5 100644 --- a/infer/tests/codetoanalyze/objc/checkers/Nullable.m +++ b/infer/tests/codetoanalyze/objc/checkers/Nullable.m @@ -193,4 +193,9 @@ int* __nullable returnsNull(); return dict; } +- (NSArray*)createArrayByAddingNilBad { + NSArray* array = @[ [NSObject alloc] ]; + return [array arrayByAddingObject:[self nullableMethod]]; +} + @end diff --git a/infer/tests/codetoanalyze/objc/checkers/issues.exp b/infer/tests/codetoanalyze/objc/checkers/issues.exp index 16e844dca..7d0588927 100644 --- a/infer/tests/codetoanalyze/objc/checkers/issues.exp +++ b/infer/tests/codetoanalyze/objc/checkers/issues.exp @@ -4,6 +4,8 @@ codetoanalyze/objc/checkers/Nullable.m, T_URLWithStringOkay, 2, DEAD_STORE, [Wri codetoanalyze/objc/checkers/Nullable.m, T_URLWithStringOkay, 2, NULL_DEREFERENCE, [start of procedure URLWithStringOkay,Skipping URLWithString:: function or method not found] codetoanalyze/objc/checkers/Nullable.m, T_assignNonnullFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is assigned null here] codetoanalyze/objc/checkers/Nullable.m, T_assignUnnanotatedFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is assigned null here] +codetoanalyze/objc/checkers/Nullable.m, T_createArrayByAddingNilBad, 2, NULLABLE_DEREFERENCE, [dereferencing the return of nullableMethod,assignment of the nullable value,definition of nullableMethod] +codetoanalyze/objc/checkers/Nullable.m, T_createArrayByAddingNilBad, 2, NULL_DEREFERENCE, [start of procedure createArrayByAddingNilBad,start of procedure nullableMethod,return from a call to T_nullableMethod] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFieldBad, 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableFieldBad] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFunctionBad, 2, NULLABLE_DEREFERENCE, [dereference of &p,assignment of the nullable value,definition of returnsNull] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFunctionBad, 2, NULL_DEREFERENCE, [start of procedure dereferenceNullableFunctionBad,Skipping returnsNull(): function or method not found]