From 50fd95bf7b1bc75a3fa7c3f722c5205497daa76b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 7 Apr 2015 20:02:50 -0400 Subject: [PATCH] Fix: ir: copy struct/seq/array NULL fields MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-fields.c | 47 ++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index e05fd324..257ad523 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -1932,13 +1932,19 @@ int bt_ctf_field_structure_copy(struct bt_ctf_field *src, g_ptr_array_set_size(struct_dst->fields, struct_src->fields->len); for (i = 0; i < struct_src->fields->len; i++) { - struct bt_ctf_field *field_copy = bt_ctf_field_copy( - g_ptr_array_index(struct_src->fields, i)); + struct bt_ctf_field *field = + g_ptr_array_index(struct_src->fields, i); + struct bt_ctf_field *field_copy = NULL; - if (!field_copy) { - ret = -1; - goto end; + if (field) { + field_copy = bt_ctf_field_copy(field); + + if (!field_copy) { + ret = -1; + goto end; + } } + g_ptr_array_index(struct_dst->fields, i) = field_copy; } end: @@ -1985,13 +1991,19 @@ int bt_ctf_field_array_copy(struct bt_ctf_field *src, g_ptr_array_set_size(array_dst->elements, array_src->elements->len); for (i = 0; i < array_src->elements->len; i++) { - struct bt_ctf_field *field_copy = bt_ctf_field_copy( - g_ptr_array_index(array_src->elements, i)); + struct bt_ctf_field *field = + g_ptr_array_index(array_src->elements, i); + struct bt_ctf_field *field_copy = NULL; - if (!field_copy) { - ret = -1; - goto end; + if (field) { + field_copy = bt_ctf_field_copy(field); + + if (!field_copy) { + ret = -1; + goto end; + } } + g_ptr_array_index(array_dst->elements, i) = field_copy; } end: @@ -2037,12 +2049,17 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src, 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)); + struct bt_ctf_field *field = + g_ptr_array_index(sequence_src->elements, i); + struct bt_ctf_field *field_copy = NULL; - if (!field_copy) { - ret = -1; - goto end; + if (field) { + field_copy = bt_ctf_field_copy(field); + + if (!field_copy) { + ret = -1; + goto end; + } } g_ptr_array_index(sequence_dst->elements, i) = field_copy; -- 2.34.1