From 0f5aa343e77f6656c9735ebb6ec56978ed2638e6 Mon Sep 17 00:00:00 2001 From: Dino Distefano Date: Mon, 9 Nov 2015 06:10:41 -0800 Subject: [PATCH] Fixed line number in the reporting of strong delegate warning Reviewed By: dulmarod Differential Revision: D2626332 fb-gh-sync-id: 5e0e661 --- infer/src/backend/errdesc.mli | 2 +- infer/src/backend/exceptions.ml | 2 +- infer/src/backend/localise.ml | 7 ++++++- infer/src/backend/localise.mli | 2 +- infer/src/clang/cFrontend_errors.ml | 17 +++++++++++------ infer/tests/utils/InferResults.java | 1 + 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/infer/src/backend/errdesc.mli b/infer/src/backend/errdesc.mli index 4411af73a..85bee57c3 100644 --- a/infer/src/backend/errdesc.mli +++ b/infer/src/backend/errdesc.mli @@ -97,7 +97,7 @@ val explain_stack_variable_address_escape : Location.t -> Sil.pvar -> Sil.dexp option -> Localise.error_desc (** explain frontend warning *) -val explain_frontend_warning : string -> string -> string -> Localise.error_desc +val explain_frontend_warning : string -> string -> Location.t -> Localise.error_desc (** explain a return statement missing *) val explain_return_statement_missing : Location.t -> Localise.error_desc diff --git a/infer/src/backend/exceptions.ml b/infer/src/backend/exceptions.ml index d9cd3caa3..6dd1ab19b 100644 --- a/infer/src/backend/exceptions.ml +++ b/infer/src/backend/exceptions.ml @@ -142,7 +142,7 @@ let recognize_exception exn = | Field_not_null_checked (desc, mloc) -> (Localise.field_not_null_checked, desc, Some mloc, Exn_user, Medium, Some Kwarning, Nocat) | Frontend_warning (name, desc, mloc) -> - (Localise.from_string name, desc, Some mloc, Exn_user, Medium, None, Nocat) + (Localise.from_string name, desc, Some mloc, Exn_user, Medium, Some Kwarning, Nocat) | Checkers (kind_s, desc) -> (Localise.from_string kind_s, desc, None, Exn_user, High, None, Prover) | Null_dereference (desc, mloc) -> diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index bb4fe8253..c66abbd7a 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -575,7 +575,12 @@ let desc_divide_by_zero expr_str loc = let desc_frontend_warning desc sugg loc = let tags = Tags.create () in - [desc ^" at line "^ loc ^". "^ sugg], None, !tags + let description = Format.sprintf + "%s %s. %s" + desc + (at_line tags loc) + sugg in + [description], None, !tags let desc_leak value_str_opt resource_opt resource_action_opt loc bucket_opt = let tags = Tags.create () in diff --git a/infer/src/backend/localise.mli b/infer/src/backend/localise.mli index fa9a5ea8e..c63c68b77 100644 --- a/infer/src/backend/localise.mli +++ b/infer/src/backend/localise.mli @@ -187,7 +187,7 @@ val desc_deallocate_static_memory : string -> Procname.t -> Location.t -> error_ val desc_divide_by_zero : string -> Location.t -> error_desc -val desc_frontend_warning : string -> string -> string -> error_desc +val desc_frontend_warning : string -> string -> Location.t -> error_desc val desc_leak : string option -> Sil.resource option -> Sil.res_action option -> diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index e29abb11c..080453d39 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -24,14 +24,19 @@ let property_checkers_list = [CFrontend_checkers.checker_strong_delegate_warning (* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *) let log_frontend_warning pdesc warn_desc = + let loc = { + Location.line = int_of_string warn_desc.loc; + Location.col = -1; + Location.file = DB.source_file_empty; + Location.nLOC = -1; + } in let errlog = Cfg.Procdesc.get_err_log pdesc in let err_desc = - Errdesc.explain_frontend_warning warn_desc.description warn_desc.suggestion - warn_desc.loc in - let exn = (Exceptions.Frontend_warning - (warn_desc.name, err_desc, - try assert false with Assert_failure x -> x)) in - Reporting.log_error_from_errlog errlog exn + Errdesc.explain_frontend_warning warn_desc.description warn_desc.suggestion loc in + let exn = Exceptions.Frontend_warning + (warn_desc.name, err_desc, + try assert false with Assert_failure x -> x) in + Reporting.log_error_from_errlog errlog exn ~loc:(Some loc) (* Call all checkers on properties of class c *) let check_for_property_errors cfg c = diff --git a/infer/tests/utils/InferResults.java b/infer/tests/utils/InferResults.java index af1e93011..7397bc3b1 100644 --- a/infer/tests/utils/InferResults.java +++ b/infer/tests/utils/InferResults.java @@ -58,6 +58,7 @@ public class InferResults { String errorType = items[2].trim(); if (errorKind.equals("ERROR") || errorType.equals("RETURN_VALUE_IGNORED") || + errorType.equals("STRONG_DELEGATE_WARNING") || errorType.equals("IMMUTABLE_CAST") || errorType.equals("PARAMETER_NOT_NULL_CHECKED") || errorType.equals("DANGLING_POINTER_DEREFERENCE") ||