Fix: Dereference null return value
[babeltrace.git] / plugins / text / pretty / print.c
index 7271c3f9acd8726a8ad8fdc534371efbba9fcda3..97e9bf11ce1aa3bb9a73cba8a60ea35da8220720 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;
                }
 
@@ -1316,14 +1317,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);
@@ -1564,15 +1574,19 @@ enum bt_component_status pretty_print_discarded_elements(
        int64_t stream_class_id;
        int64_t stream_id;
        bool is_discarded_events;
+       int64_t count;
+       struct bt_ctf_clock_value *clock_value = NULL;
 
        /* Stream name */
        switch (bt_notification_get_type(notif)) {
        case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
                stream = bt_notification_discarded_events_get_stream(notif);
+               count = bt_notification_discarded_events_get_count(notif);
                is_discarded_events = true;
                break;
        case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
                stream = bt_notification_discarded_packets_get_stream(notif);
+               count = bt_notification_discarded_packets_get_count(notif);
                is_discarded_events = false;
                break;
        default:
@@ -1606,26 +1620,26 @@ enum bt_component_status pretty_print_discarded_elements(
         * with Babeltrace 1.
         */
        fprintf(stderr,
-               "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s between [",
+               "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s between [",
                bt_common_color_fg_yellow(),
                bt_common_color_bold(),
                bt_common_color_reset(),
                bt_common_color_fg_yellow(),
-               is_discarded_events ?
-                       bt_notification_discarded_events_get_count(notif) :
-                       bt_notification_discarded_packets_get_count(notif),
-               is_discarded_events ? "events" : "packets");
+               count, is_discarded_events ? "event" : "packet",
+               count == 1 ? "" : "s");
        g_string_assign(pretty->string, "");
-       print_timestamp_wall(pretty,
-               is_discarded_events ?
+       clock_value = is_discarded_events ?
                bt_notification_discarded_events_get_begin_clock_value(notif) :
-               bt_notification_discarded_packets_get_begin_clock_value(notif));
+               bt_notification_discarded_packets_get_begin_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       BT_PUT(clock_value);
        fprintf(stderr, "%s] and [", pretty->string->str);
        g_string_assign(pretty->string, "");
-       print_timestamp_wall(pretty,
-               is_discarded_events ?
+       clock_value = is_discarded_events ?
                bt_notification_discarded_events_get_end_clock_value(notif) :
-               bt_notification_discarded_packets_get_end_clock_value(notif));
+               bt_notification_discarded_packets_get_end_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       BT_PUT(clock_value);
        fprintf(stderr, "%s] in trace \"%s\" ",
                pretty->string->str, trace_name);
 
@@ -1665,5 +1679,6 @@ enum bt_component_status pretty_print_discarded_elements(
        bt_put(stream);
        bt_put(stream_class);
        bt_put(trace);
+       bt_put(clock_value);
        return ret;
 }
This page took 0.024588 seconds and 4 git commands to generate.