diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index 03add7bca..6f955f96f 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -24,9 +24,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct if Typ.Procname.is_java callee_pname then not (Typ.Procname.java_is_static callee_pname) else Option.exists - ~f:(fun attributes -> - attributes.ProcAttributes.is_objc_instance_method - || attributes.ProcAttributes.is_cpp_instance_method) + ~f:(fun attributes -> attributes.ProcAttributes.is_cpp_instance_method) (Specs.proc_resolve_attributes callee_pname) diff --git a/infer/tests/codetoanalyze/objc/checkers/Nullable.m b/infer/tests/codetoanalyze/objc/checkers/Nullable.m index bcedc48b5..5fa9267ee 100644 --- a/infer/tests/codetoanalyze/objc/checkers/Nullable.m +++ b/infer/tests/codetoanalyze/objc/checkers/Nullable.m @@ -11,7 +11,7 @@ int* __nullable returnsNull(); @interface T : NSObject -- (void)assignUnnanotatedFieldToNullBad; +- (NSObject* _Nullable)nullableMethod; @end @implementation T { @@ -83,23 +83,32 @@ int* __nullable returnsNull(); } } -- (void)dereferenceNullableMethodBad { +- (void)dereferenceNullableFunctionBad { int* p = returnsNull(); *p = 42; } -- (void)dereferenceNullableMethod1Ok { +- (void)dereferenceNullableFunction1Ok { int* p = returnsNull(); if (p) { *p = 42; } } -- (void)dereferenceNullableMethod2Ok { +- (void)dereferenceNullableFunction2Ok { int* p = returnsNull(); if (p != nil) { *p = 42; } } +- (NSObject* _Nullable)nullableMethod { + return nil; +} + +- (NSString*)dereferenceNullableMethodOkay { + NSObject* object = [self nullableMethod]; + return [object description]; +} + @end diff --git a/infer/tests/codetoanalyze/objc/checkers/issues.exp b/infer/tests/codetoanalyze/objc/checkers/issues.exp index 4d05f0320..edadaab80 100644 --- a/infer/tests/codetoanalyze/objc/checkers/issues.exp +++ b/infer/tests/codetoanalyze/objc/checkers/issues.exp @@ -3,8 +3,8 @@ codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestFor 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_dereferenceNullableFieldBad, 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableFieldBad] -codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableMethodBad, 2, NULLABLE_DEREFERENCE, [deference of &p,assignment of the nullable value,definition of returnsNull] -codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableMethodBad, 2, NULL_DEREFERENCE, [start of procedure dereferenceNullableMethodBad,Skipping returnsNull(): function or method not found] +codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFunctionBad, 2, NULLABLE_DEREFERENCE, [deference 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] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is compared to null here] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 2, NULL_DEREFERENCE, [start of procedure dereferenceUnnanotatedFieldAfterTestForNullBad,Condition is true] codetoanalyze/objc/checkers/Nullable.m, T_testNonnullFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here]