From: Mathieu Desnoyers Date: Tue, 15 Aug 2017 21:17:14 +0000 (-0400) Subject: Fix: handle unknown enum mapping X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=83ef32056ebf24b82dd975acf9f0ef6da0d944c6 Fix: handle unknown enum mapping 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 --- 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) {