Fix: handle unknown enum mapping
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 15 Aug 2017 21:17:14 +0000 (17:17 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 15 Aug 2017 22:04:26 +0000 (18:04 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/text/pretty/print.c

index 97e9bf11ce1aa3bb9a73cba8a60ea35da8220720..11cd18831ab67fecdfa821a7f53418238a0553de 100644 (file)
@@ -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);
        }
                iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
                                enumeration_field_type, value);
        }
+       g_string_append(pretty->string, "( ");
        if (!iter) {
        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, "<unknown>");
+               if (pretty->use_colors) {
+                       g_string_append(pretty->string, COLOR_RST);
+               }
+               goto skip_loop;
        }
        }
-       g_string_append(pretty->string, "( ");
        for (;;) {
                const char *mapping_name;
 
        for (;;) {
                const char *mapping_name;
 
@@ -875,15 +881,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty,
                        break;
                }
        }
                        break;
                }
        }
-       if (!nr_mappings) {
-               if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_UNKNOWN);
-               }
-               g_string_append(pretty->string, "<unknown>");
-               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) {
        g_string_append(pretty->string, " : container = ");
        ret = print_integer(pretty, container_field);
        if (ret != BT_COMPONENT_STATUS_OK) {
This page took 0.025779 seconds and 4 git commands to generate.