From 08586f3e813e843515f4d62ea33dc88b61d8f921 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 8 Jun 2017 10:50:06 -0700 Subject: [PATCH] [checkers] logging to summary in printf args checker Reviewed By: jeremydubreil Differential Revision: D5030247 fbshipit-source-id: 26a280c --- infer/src/backend/symExec.ml | 8 ---- infer/src/checkers/printfArgs.ml | 41 +++++-------------- infer/src/checkers/printfArgs.mli | 13 ------ .../codetoanalyze/java/checkers/issues.exp | 5 ++- 4 files changed, 14 insertions(+), 53 deletions(-) diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index f3895bdd6..c7001ae67 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -802,13 +802,6 @@ let normalize_params tenv pdesc prop actual_params = let prop, args = List.fold ~f:norm_arg ~init:(prop, []) actual_params in (prop, List.rev args) -let do_error_checks tenv node_opt instr pname pdesc = match node_opt with - | Some node -> - if Config.curr_language_is Config.Java then - PrintfArgs.check_printf_args_ok tenv node instr pname pdesc - | None -> - () - let add_strexp_to_footprint tenv strexp abduced_pv typ prop = let abduced_lvar = Exp.Lvar abduced_pv in let lvar_pt_fpvar = @@ -1115,7 +1108,6 @@ let rec sym_exec tenv current_pdesc _instr (prop_: Prop.normal Prop.t) path proc_call resolved_summary (call_args prop_ callee_pname norm_args ret_id loc) end | Java callee_pname_java -> - do_error_checks tenv (Paths.Path.curr_node path) instr current_pname current_pdesc; let norm_prop, norm_args = normalize_params tenv current_pname prop_ actual_params in let url_handled_args = call_constructor_url_update_args callee_pname norm_args in diff --git a/infer/src/checkers/printfArgs.ml b/infer/src/checkers/printfArgs.ml index 2084290b6..d419bf148 100644 --- a/infer/src/checkers/printfArgs.ml +++ b/infer/src/checkers/printfArgs.ml @@ -40,10 +40,6 @@ let printf_like_functions = vararg_pos = Some 3 }; ] -let add_printf_like_function plf = - printf_like_functions := plf :: !printf_like_functions - - let printf_like_function (proc_name: Typ.Procname.t): printf_signature option = List.find @@ -109,11 +105,14 @@ let rec format_string_type_names fmt_type:: format_string_type_names fmt_string (Str.match_end ()) with Not_found -> [] -let check_printf_args_ok tenv +let check_printf_args_ok + tenv (node: Procdesc.Node.t) (instr: Sil.instr) (proc_name: Typ.Procname.t) - (proc_desc: Procdesc.t): unit = + (proc_desc: Procdesc.t) + summary + : unit = (* Check if format string lines up with arguments *) let rec check_type_names instr_loc n_arg instr_proc_name fmt_type_names arg_type_names = @@ -129,12 +128,8 @@ let check_printf_args_ok tenv n_arg (default_format_type_name ft) gt in - Checkers.ST.report_error tenv - proc_name - proc_desc - Localise.checkers_printf_args - instr_loc - description + let exn = Exceptions.Checkers (description, Localise.verbatim_desc description) in + Reporting.log_error_from_summary summary ~loc:instr_loc exn else check_type_names instr_loc (n_arg + 1) instr_proc_name fs gs | [], [] -> () @@ -143,12 +138,8 @@ let check_printf_args_ok tenv "format string arguments don't mach provided arguments in %s at line %s" instr_name instr_line in - Checkers.ST.report_error tenv - proc_name - proc_desc - Localise.checkers_printf_args - instr_loc - description in + let exn = Exceptions.Checkers (description, Localise.verbatim_desc description) in + Reporting.log_error_from_summary summary ~loc:instr_loc exn in (* Get the array ivar for a given nvar *) let rec array_ivar instrs nvar = @@ -208,16 +199,6 @@ let check_printf_args_ok tenv let callback_printf_args { Callbacks.tenv; proc_desc; summary } : Specs.summary = let proc_name = Procdesc.get_proc_name proc_desc in - Procdesc.iter_instrs (fun n i -> check_printf_args_ok tenv n i proc_name proc_desc) proc_desc; + Procdesc.iter_instrs + (fun n i -> check_printf_args_ok tenv n i proc_name proc_desc summary) proc_desc; summary - -(* -let printf_signature_to_string - (printf: printf_signature): string = - Printf.sprintf - "{%s; %d [%s] %s}" - printf.unique_id - printf.format_pos - (String.concat ~sep:"," (List.map ~f:string_of_int printf.fixed_pos)) - (match printf.vararg_pos with | Some i -> string_of_int i | _ -> "-") -*) diff --git a/infer/src/checkers/printfArgs.mli b/infer/src/checkers/printfArgs.mli index e332dbcb2..6ae0b9039 100644 --- a/infer/src/checkers/printfArgs.mli +++ b/infer/src/checkers/printfArgs.mli @@ -9,17 +9,4 @@ open! IStd - -type printf_signature = { - unique_id: string; - format_pos: int; - fixed_pos: int list; - vararg_pos: int option -} - -val add_printf_like_function : printf_signature -> unit - -val check_printf_args_ok : - Tenv.t -> Procdesc.Node.t -> Sil.instr -> Typ.Procname.t -> Procdesc.t -> unit - val callback_printf_args: Callbacks.proc_callback_t diff --git a/infer/tests/codetoanalyze/java/checkers/issues.exp b/infer/tests/codetoanalyze/java/checkers/issues.exp index 012b8884b..a61115c81 100644 --- a/infer/tests/codetoanalyze/java/checkers/issues.exp +++ b/infer/tests/codetoanalyze/java/checkers/issues.exp @@ -43,8 +43,9 @@ codetoanalyze/java/checkers/NullableSuggest.java, void NullableSuggest.assignNul codetoanalyze/java/checkers/NullableSuggest.java, void NullableSuggest.compareNullToFieldBad(), 2, FIELD_SHOULD_BE_NULLABLE, [Field obj0 is compared to null here] codetoanalyze/java/checkers/NullableSuggest.java, void NullableSuggest.multipleChainsAlwaysSelectShortestBad(boolean), 6, FIELD_SHOULD_BE_NULLABLE, [Field obj0 could be assigned here,Variable is assigned null here] codetoanalyze/java/checkers/PrintfArgsChecker.java, void PrintfArgsChecker.formatStringIsNotLiteral(PrintStream), 2, CHECKERS_PRINTF_ARGS, [Format string must be string literal] -codetoanalyze/java/checkers/PrintfArgsChecker.java, void PrintfArgsChecker.stringInsteadOfInteger(PrintStream), 1, CHECKERS_PRINTF_ARGS, [printf(...) at line 40: parameter 2 is expected to be of type java.lang.Integer but java.lang.String was given.] -codetoanalyze/java/checkers/PrintfArgsChecker.java, void PrintfArgsChecker.wrongNumberOfArguments(PrintStream), 1, CHECKERS_PRINTF_ARGS, [format string arguments don't mach provided arguments in printf(...) at line 44] +codetoanalyze/java/checkers/PrintfArgsChecker.java, void PrintfArgsChecker.stringInsteadOfInteger(PrintStream), 1, printf(...) at line 40: parameter 2 is expected to be of type java.lang.Integer but java.lang.String was given., [] +codetoanalyze/java/checkers/PrintfArgsChecker.java, void PrintfArgsChecker.wrongNumberOfArguments(PrintStream), 1, format string arguments don't mach provided arguments in printf(...) at line 44, [] +codetoanalyze/java/checkers/PrintfArgsChecker.java, void SuppressedPrintfArgsChecker.classSuppressed(PrintStream), 1, printf(...) at line 68: parameter 2 is expected to be of type java.lang.Integer but java.lang.String was given., [] codetoanalyze/java/checkers/TwoCheckersExample.java, List TwoCheckersExample.shouldRaiseImmutableCastError(), 0, CHECKERS_IMMUTABLE_CAST, [Method shouldRaiseImmutableCastError() returns class com.google.common.collect.ImmutableList but the return type is class java.util.List. Make sure that users of this method do not try to modify the collection.] codetoanalyze/java/checkers/TwoCheckersExample.java, List TwoCheckersExample.shouldRaisePerformanceCriticalError(), 1, CHECKERS_CALLS_EXPENSIVE_METHOD, [] codetoanalyze/java/checkers/UiThreads.java, void UiThreads.callForNonUiThreadBad1(), 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, []