diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index d091e3df1..f4cd67fde 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -348,11 +348,11 @@ let sil_method_annotation_of_args args : Typ.method_annotation = let mk_annot param_name annot_name = let annot = { Typ.class_name = annot_name; Typ.parameters = [param_name]; } in annot, default_visibility in - let arg_to_sil_annot acc (arg_name, type_ptr) = + let arg_to_sil_annot (arg_name, type_ptr) acc = if CFrontend_utils.Ast_utils.is_type_nullable type_ptr then [mk_annot arg_name Annotations.nullable] :: acc - else acc in - let param_annots = IList.fold_left arg_to_sil_annot [] args in + else Typ.item_annotation_empty::acc in + let param_annots = IList.fold_right arg_to_sil_annot args [] in (* TODO: parse annotations on return value *) let retval_annot = [] in retval_annot, param_annots diff --git a/infer/tests/codetoanalyze/objc/errors/npe/nullable.m b/infer/tests/codetoanalyze/objc/errors/npe/nullable.m index 68f5d5f1f..129bb66ec 100644 --- a/infer/tests/codetoanalyze/objc/errors/npe/nullable.m +++ b/infer/tests/codetoanalyze/objc/errors/npe/nullable.m @@ -38,6 +38,20 @@ A* derefNullableParamOk(A* __nullable param) { return param; } +int parameter_nullable_ok(NSString* body, + __nullable NSString* linkTapAction, + A* options) { + return options->fld; +} + +int parameter_nullable_bug(__nullable A* options, + NSAttributedString* body, + NSString* linkTapAction) + +{ + return options->fld; +} + int readNullableParamPropertyOk(B* __nullable param) { return param.prop; } void writeNullableParamPropertyOk(B* __nullable param) { param.prop = 7; } diff --git a/infer/tests/endtoend/objc/NullableTest.java b/infer/tests/endtoend/objc/NullableTest.java index dd184bead..a70b02396 100644 --- a/infer/tests/endtoend/objc/NullableTest.java +++ b/infer/tests/endtoend/objc/NullableTest.java @@ -49,8 +49,9 @@ public class NullableTest { public void nullDereferenceTest() throws InterruptedException, IOException, InferException { InferResults inferResults = InferRunner.runInferC(inferCmdNPD); String[] procedures = { - "derefNullableParamDirect", - "derefNullableParamIndirect" + "derefNullableParamDirect", + "derefNullableParamIndirect", + "parameter_nullable_bug" }; assertThat( "Results should contain null pointer dereference error",