[checkers] logging to summary in printf args checker

Reviewed By: jeremydubreil

Differential Revision: D5030247

fbshipit-source-id: 26a280c
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent d4ee640dd6
commit 08586f3e81

@ -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

@ -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 | _ -> "-")
*)

@ -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

@ -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, []

Loading…
Cancel
Save