From 446b22467c6565d00bd5acf7df818e8efbdae16d Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.maroneze@cea.fr>
Date: Thu, 16 Jul 2020 22:28:52 +0200
Subject: [PATCH] [MdR] do not emit location in SARIF if unknown

---
 src/plugins/markdown-report/sarif_gen.ml | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml
index 16c8a3644bc..b5cd461e6b0 100644
--- a/src/plugins/markdown-report/sarif_gen.ml
+++ b/src/plugins/markdown-report/sarif_gen.ml
@@ -98,6 +98,10 @@ let make_message alarm annot remark =
   in
   Message.create ~text ~richText ()
 
+let opt_physical_location_of_loc loc =
+  if loc = Cil_datatype.Location.unknown then []
+  else [ Location.of_loc loc ]
+
 let gen_results remarks =
   let treat_alarm _e kf s ~rank:_ alarm annot (i, rules, content) =
     let prop = Property.ip_of_code_annot_single kf s annot in
@@ -109,7 +113,7 @@ let gen_results remarks =
     let level = level_of_status (Property_status.Feedback.get prop) in
     let remark = get_remark remarks label in
     let message = make_message alarm annot remark in
-    let locations = [ Location.of_loc (Cil_datatype.Stmt.loc s) ] in
+    let locations = opt_physical_location_of_loc (Cil_datatype.Stmt.loc s) in
     let res =
       Sarif_result.create ~level ~ruleId ~message ~locations ()
     in
@@ -131,7 +135,7 @@ let make_ip_message ip =
 let gen_status ip =
   let status = Property_status.Feedback.get ip in
   let level = level_of_status status in
-  let locations = [ Location.of_loc (Property.location ip) ] in
+  let locations = opt_physical_location_of_loc (Property.location ip) in
   let message = make_ip_message ip in
   Sarif_result.create ~level ~locations ~message ()
 
-- 
GitLab