sink.text.pretty: abort on unknown field class type
[babeltrace.git] / src / plugins / ctf / common / msg-iter / msg-iter.cpp
index 4efc5ed61b9b6e6786750cbed3461cd3a1f40d6d..33ad4a27afacab558566cb7ef19c29d0f3042d4a 100644 (file)
@@ -7,27 +7,25 @@
  * Babeltrace - CTF message iterator
  */
 
+#include <glib.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include <babeltrace2/babeltrace.h>
+
 #define BT_COMP_LOG_SELF_COMP (msg_it->self_comp)
 #define BT_LOG_OUTPUT_LEVEL   (msg_it->log_level)
 #define BT_LOG_TAG            "PLUGIN/CTF/MSG-ITER"
 #include "logging/comp-logging.h"
 
-#include <stdint.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdbool.h>
 #include "common/assert.h"
-#include <string.h>
-#include <babeltrace2/babeltrace.h>
 #include "common/common.h"
-#include <glib.h>
-#include <stdlib.h>
 
-#include "msg-iter.hpp"
 #include "../bfcr/bfcr.hpp"
-
-struct ctf_msg_iter;
+#include "msg-iter.hpp"
+#include "plugins/ctf/common/metadata/ctf-meta.hpp"
 
 /* A visit stack entry */
 struct stack_entry
@@ -49,8 +47,6 @@ struct stack_entry
     size_t index;
 };
 
-struct ctf_msg_iter;
-
 /* Visit stack */
 struct stack
 {
@@ -1793,6 +1789,20 @@ end:
                  msg_it->default_clock_snapshot);
 }
 
+/*
+ * Ensure the message iterator's `stored_values` array is large enough to
+ * accommodate `storing_index`.
+ *
+ * We may need more slots in the array than initially allocated if more
+ * metadata arrives along the way.
+ */
+static void ensure_stored_values_size(ctf_msg_iter *msg_it, uint64_t storing_index)
+{
+    if (G_UNLIKELY(storing_index >= msg_it->stored_values->len)) {
+        g_array_set_size(msg_it->stored_values, msg_it->meta.tc->stored_value_count);
+    }
+}
+
 static enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value, struct ctf_field_class *fc,
                                                 void *data)
 {
@@ -1862,6 +1872,7 @@ update_def_clock:
     }
 
     if (G_UNLIKELY(int_fc->storing_index >= 0)) {
+        ensure_stored_values_size(msg_it, int_fc->storing_index);
         bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) = value;
     }
 
@@ -1948,6 +1959,7 @@ static enum bt_bfcr_status bfcr_signed_int_cb(int64_t value, struct ctf_field_cl
     BT_ASSERT_DBG(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE);
 
     if (G_UNLIKELY(int_fc->storing_index >= 0)) {
+        ensure_stored_values_size(msg_it, int_fc->storing_index);
         bt_g_array_index(msg_it->stored_values, uint64_t, (uint64_t) int_fc->storing_index) =
             (uint64_t) value;
     }
@@ -2729,7 +2741,7 @@ enum ctf_msg_iter_status ctf_msg_iter_get_next_message(struct ctf_msg_iter *msg_
             }
             goto end;
         case STATE_EMIT_MSG_DISCARDED_EVENTS:
-            /* create_msg_discared_events() logs errors */
+            /* create_msg_discarded_events() logs errors */
             *message = create_msg_discarded_events(msg_it);
 
             if (!*message) {
@@ -2738,7 +2750,7 @@ enum ctf_msg_iter_status ctf_msg_iter_get_next_message(struct ctf_msg_iter *msg_
 
             goto end;
         case STATE_EMIT_MSG_DISCARDED_PACKETS:
-            /* create_msg_discared_packets() logs errors */
+            /* create_msg_discarded_packets() logs errors */
             *message = create_msg_discarded_packets(msg_it);
 
             if (!*message) {
This page took 0.024264 seconds and 4 git commands to generate.