From 4a10024dfbe356be2083e0a16421a9ac5474220f Mon Sep 17 00:00:00 2001 From: "Mark R. Tuttle" <mrtuttle@amazon.com> Date: Wed, 24 Jul 2019 13:10:50 -0400 Subject: [PATCH 1/2] Patch goto-analyzer reachable-functions json and xml output. Source locations occassionally omit a line number, and printing an empty string in the json and xml output renders the output unparsable. This patch uses "0" in place of the empty string in the output. --- .../unreachable_instructions.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index 544b6c8be6f..f32dc47815d 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -249,14 +249,21 @@ static void json_output_function( const source_locationt &last_location, json_arrayt &dest) { + // source locations occassionally omit line numbers + // an empty string makes json unparsable + std::string first_line = id2string(first_location.get_line()); + std::string last_line = id2string(last_location.get_line()); + first_line = first_line.empty() ? "0" : first_line; + last_line = last_line.empty() ? "0" : last_line; + json_objectt entry{ {"function", json_stringt(function)}, {"file name", json_stringt(concat_dir_file( id2string(first_location.get_working_directory()), id2string(first_location.get_file())))}, - {"first line", json_numbert(id2string(first_location.get_line()))}, - {"last line", json_numbert(id2string(last_location.get_line()))}}; + {"first line", json_numbert(first_line)}, + {"last line", json_numbert(last_line)}}; dest.push_back(std::move(entry)); } @@ -269,13 +276,20 @@ static void xml_output_function( { xmlt &x=dest.new_element("function"); + // source locations occassionally omit line numbers + // an empty string makes xml unparsable + std::string first_line = id2string(first_location.get_line()); + std::string last_line = id2string(last_location.get_line()); + first_line = first_line.empty() ? "0" : first_line; + last_line = last_line.empty() ? "0" : last_line; + x.set_attribute("name", id2string(function)); x.set_attribute("file name", concat_dir_file( id2string(first_location.get_working_directory()), id2string(first_location.get_file()))); - x.set_attribute("first line", id2string(first_location.get_line())); - x.set_attribute("last line", id2string(last_location.get_line())); + x.set_attribute("first line", first_line); + x.set_attribute("last line", last_line); } static void list_functions( From 3f79983a1c20632602c23e79f013ba56cfdfdb2d Mon Sep 17 00:00:00 2001 From: "Mark R. Tuttle" <mrtuttle@amazon.com> Date: Thu, 25 Jul 2019 15:44:08 -0400 Subject: [PATCH 2/2] Fix clang-format complaints --- src/goto-analyzer/unreachable_instructions.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index f32dc47815d..c254c500cd6 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -256,14 +256,13 @@ static void json_output_function( first_line = first_line.empty() ? "0" : first_line; last_line = last_line.empty() ? "0" : last_line; - json_objectt entry{ - {"function", json_stringt(function)}, - {"file name", - json_stringt(concat_dir_file( - id2string(first_location.get_working_directory()), - id2string(first_location.get_file())))}, - {"first line", json_numbert(first_line)}, - {"last line", json_numbert(last_line)}}; + json_objectt entry{{"function", json_stringt(function)}, + {"file name", + json_stringt(concat_dir_file( + id2string(first_location.get_working_directory()), + id2string(first_location.get_file())))}, + {"first line", json_numbert(first_line)}, + {"last line", json_numbert(last_line)}}; dest.push_back(std::move(entry)); }