From af380708aa74fbe3148459048b291f7458b137e8 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 6 Feb 2020 08:05:48 -0800 Subject: [PATCH] [SelfInBlock] Fixing bugs in checking nullable annotation when reporting strongSelfNotChecked Summary: Fixing bugs in the report_unchecked_strongself_issues_on_args function: we were not recursing if the first arg wasn't a var, and we were not removing the annotations from self in instance methods. Here we fix those issues. Reviewed By: ngorogiannis Differential Revision: D19662886 fbshipit-source-id: 03820961e --- infer/src/checkers/SelfInBlock.ml | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/infer/src/checkers/SelfInBlock.ml b/infer/src/checkers/SelfInBlock.ml index 9433d83ad..6686dae8f 100644 --- a/infer/src/checkers/SelfInBlock.ml +++ b/infer/src/checkers/SelfInBlock.ml @@ -294,26 +294,33 @@ module TransferFunctions = struct (F.sprintf "passed to %s" (Procname.to_simplified_string pname)) var in - let rec report_on_non_nullable_arg ?(annots = []) args = - match (annots, args) with - | annot :: annot_rest, (Exp.Var var, _) :: rest when not (Annotations.ia_is_nullable annot) -> - report_issue var ; - report_on_non_nullable_arg ~annots:annot_rest rest - | [], (Exp.Var var, _) :: rest -> - report_issue var ; report_on_non_nullable_arg rest + let rec report_on_non_nullable_arg ?annotations args = + match (annotations, args) with + | Some (annot :: annot_rest), (arg, _) :: rest -> + ( match arg with + | Exp.Var var when not (Annotations.ia_is_nullable annot) -> + report_issue var + | _ -> + () ) ; + report_on_non_nullable_arg ~annotations:annot_rest rest + | None, (arg, _) :: rest -> + (match arg with Exp.Var var -> report_issue var | _ -> ()) ; + report_on_non_nullable_arg rest | _ -> () in let proc_desc_opt = Ondemand.get_proc_desc pname in + let annotations = get_annotations proc_desc_opt in let args = if is_objc_instance proc_desc_opt then match args with _ :: rest -> rest | [] -> [] else args in - match get_annotations proc_desc_opt with - | Some annotations -> - report_on_non_nullable_arg ~annots:annotations args - | None -> - report_on_non_nullable_arg args + let annotations = + if is_objc_instance proc_desc_opt then + match annotations with Some (_ :: rest) -> Some rest | _ -> annotations + else annotations + in + report_on_non_nullable_arg ?annotations args let exec_instr (astate : Domain.t) {ProcData.summary} _cfg_node (instr : Sil.instr) =