Fix: handle unknown enum mapping
[babeltrace.git] / plugins / text / pretty / print.c
index e698f4bd6671e87e6cec52bc115e25d42068e03a..11cd18831ab67fecdfa821a7f53418238a0553de 100644 (file)
@@ -191,9 +191,10 @@ void print_timestamp_wall(struct pretty_component *pretty,
                struct tm tm;
                time_t time_s = (time_t) ts_sec_abs;
 
-               if (is_negative) {
+               if (is_negative && !pretty->negative_timestamp_warning_done) {
                        // TODO: log instead
                        fprintf(stderr, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
+                       pretty->negative_timestamp_warning_done = true;
                        goto seconds;
                }
 
@@ -848,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, "<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;
 
@@ -874,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, "<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) {
@@ -1316,14 +1315,23 @@ enum bt_component_status print_field(struct pretty_component *pretty,
        case CTF_TYPE_ENUM:
                return print_enum(pretty, field);
        case CTF_TYPE_STRING:
+       {
+               const char *str;
+
+               str = bt_ctf_field_string_get_value(field);
+               if (!str) {
+                       return BT_COMPONENT_STATUS_ERROR;
+               }
+
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_STRING_VALUE);
                }
-               print_escape_string(pretty, bt_ctf_field_string_get_value(field));
+               print_escape_string(pretty, str);
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_RST);
                }
                return BT_COMPONENT_STATUS_OK;
+       }
        case CTF_TYPE_STRUCT:
                return print_struct(pretty, field, print_names, filter_fields,
                                filter_array_len);
This page took 0.024682 seconds and 4 git commands to generate.