From 83ef32056ebf24b82dd975acf9f0ef6da0d944c6 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 15 Aug 2017 17:17:14 -0400 Subject: [PATCH] Fix: handle unknown enum mapping MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Found by Coverity: At condition nr_mappings, the value of nr_mappings must be at least 1. The condition !nr_mappings cannot be true. CID 1376163 (#1 of 1): Logically dead code (DEADCODE) dead_error_line: Execution cannot reach this statement: if (pretty->use_colors) { Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- plugins/text/pretty/print.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 97e9bf11..11cd1883 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -849,11 +849,17 @@ enum bt_component_status print_enum(struct pretty_component *pretty, iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value( enumeration_field_type, value); } + g_string_append(pretty->string, "( "); if (!iter) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; + if (pretty->use_colors) { + g_string_append(pretty->string, COLOR_UNKNOWN); + } + g_string_append(pretty->string, ""); + if (pretty->use_colors) { + g_string_append(pretty->string, COLOR_RST); + } + goto skip_loop; } - g_string_append(pretty->string, "( "); for (;;) { const char *mapping_name; @@ -875,15 +881,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty, break; } } - if (!nr_mappings) { - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_UNKNOWN); - } - g_string_append(pretty->string, ""); - if (pretty->use_colors) { - g_string_append(pretty->string, COLOR_RST); - } - } +skip_loop: g_string_append(pretty->string, " : container = "); ret = print_integer(pretty, container_field); if (ret != BT_COMPONENT_STATUS_OK) { -- 2.34.1