Fix: ir: seq copy: initialize internal array
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 21 Mar 2015 00:28:53 +0000 (20:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 28 Apr 2015 19:15:35 +0000 (15:15 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-fields.c

index f524d5dbb8ce2fef86b935a5d4e69226e4c1999d..55316f49d88e52960b23807127f109255ae4544d 100644 (file)
@@ -1975,12 +1975,38 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src,
 {
        int ret = 0, i;
        struct bt_ctf_field_sequence *sequence_src, *sequence_dst;
+       struct bt_ctf_field *src_length;
+       struct bt_ctf_field *dst_length;
 
        sequence_src = container_of(src, struct bt_ctf_field_sequence, parent);
        sequence_dst = container_of(dst, struct bt_ctf_field_sequence, parent);
 
-       g_ptr_array_set_size(sequence_dst->elements,
-               sequence_src->elements->len);
+       src_length = bt_ctf_field_sequence_get_length(src);
+
+       if (!src_length) {
+               /* no length set yet: keep destination sequence empty */
+               goto end;
+       }
+
+       /* copy source length */
+       dst_length = bt_ctf_field_copy(src_length);
+       bt_ctf_field_put(src_length);
+
+       if (!dst_length) {
+               ret = -1;
+               goto end;
+       }
+
+       /* this will initialize the destination sequence's internal array */
+       ret = bt_ctf_field_sequence_set_length(dst, dst_length);
+       bt_ctf_field_put(dst_length);
+
+       if (ret) {
+               goto end;
+       }
+
+       assert(sequence_dst->elements->len == sequence_src->elements->len);
+
        for (i = 0; i < sequence_src->elements->len; i++) {
                struct bt_ctf_field *field_copy = bt_ctf_field_copy(
                        g_ptr_array_index(sequence_src->elements, i));
@@ -1989,6 +2015,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src,
                        ret = -1;
                        goto end;
                }
+
                g_ptr_array_index(sequence_dst->elements, i) = field_copy;
        }
 end:
This page took 0.026018 seconds and 4 git commands to generate.