diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index 25c5cda110a..7d43b652f55 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -429,39 +429,22 @@ module ExpensiveAnnotationSpec = struct } end -(* parse user-defined specs from .inferconfig *) -let parse_user_defined_specs = function - | `List user_specs -> - let parse_user_spec json = - let open Yojson.Safe in - let sources = Util.member "sources" json |> Util.to_list |> List.map ~f:Util.to_string in - let sinks = Util.member "sinks" json |> Util.to_list |> List.map ~f:Util.to_string in - let sanitizers = - match Util.member "sanitizers" json with - | `List s -> - List.map ~f:Util.to_string s - | _ -> - L.user_warning "Expected a list of strings as sanitizers, ignoring.\n" ; - [] - in - (sources, sinks, sanitizers) - in - List.map ~f:parse_user_spec user_specs - | _ -> - L.user_warning "Expected a list as custom annotations, ignoring.\n" ; - [] +type user_defined_spec = + {sources: string list; sinks: string list; sanitizers: string list [@yojson.default []]} +[@@deriving of_yojson] +type user_defined_specs = user_defined_spec list [@@deriving of_yojson] let annot_specs = - let parse_one_spec (str_src_annots, str_snk_annots, str_sanitizer_annots) = - List.map - ~f:(fun str_snk_annot -> - StandardAnnotationSpec.from_annotations str_src_annots str_snk_annot str_sanitizer_annots ) - str_snk_annots + let make_standard_spec_from_user_spec {sources; sinks; sanitizers} = + List.map ~f:(fun sink -> StandardAnnotationSpec.from_annotations sources sink sanitizers) sinks in let user_defined_specs = - parse_user_defined_specs Config.annotation_reachability_custom_pairs - |> List.map ~f:parse_one_spec + let specs = + try user_defined_specs_of_yojson Config.annotation_reachability_custom_pairs + with _ -> L.die ExternalError "Could not parse annotation reachability custom pairs@." + in + List.map specs ~f:make_standard_spec_from_user_spec in let user_defined_specs = List.concat user_defined_specs in [ (Language.Clang, CxxAnnotationSpecs.from_config ())