Fix: bfcr_get_sequence_length_cb(): do not set text array's length
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 23 Apr 2019 23:54:42 +0000 (19:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:39 +0000 (18:19 -0400)
Issue
=====
In `msg-iter.c`, bfcr_get_sequence_length_cb() gets called when starting
the decoding of any sequence, including text sequences. However, text
arrays are translated into trace IR string field classes.

bfcr_get_sequence_length_cb() calls bt_field_dynamic_array_set_length()
unconditionally, but its field argument can be a string field at this
point. This is a precondition break.

Solution
========
In bt_field_dynamic_array_set_length(), only call
bt_field_dynamic_array_set_length() if the CTF IR field class is NOT a
text sequence. I'm also adding an assertion to confirm that the trace IR
field is a dynamic array field.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/ctf/common/msg-iter/msg-iter.c

index 0d41638e988cfa88a02a6eee3434932214567e78..9f3dbad984c014ead0a4ec078f80d7b208c4fb09 100644 (file)
@@ -2288,11 +2288,23 @@ int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *data)
                seq_fc->stored_length_index);
        seq_field = stack_top(notit->stack)->base;
        BT_ASSERT(seq_field);
-       ret = bt_field_dynamic_array_set_length(seq_field, (uint64_t) length);
-       if (ret) {
-               BT_LOGE("Cannot set dynamic array field's length field: "
-                       "notit-addr=%p, field-addr=%p, "
-                       "length=%" PRIu64, notit, seq_field, length);
+
+       /*
+        * bfcr_get_sequence_length_cb() also gets called back for a
+        * text sequence, but the destination field is a string field.
+        * Only set the field's sequence length if the destination field
+        * is a sequence field.
+        */
+       if (!seq_fc->base.is_text) {
+               BT_ASSERT(bt_field_get_class_type(seq_field) ==
+                       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
+               ret = bt_field_dynamic_array_set_length(seq_field,
+                       (uint64_t) length);
+               if (ret) {
+                       BT_LOGE("Cannot set dynamic array field's length field: "
+                               "notit-addr=%p, field-addr=%p, "
+                               "length=%" PRIu64, notit, seq_field, length);
+               }
        }
 
        return length;
This page took 0.027541 seconds and 4 git commands to generate.