From: Philippe Proulx Date: Wed, 8 Apr 2015 00:02:50 +0000 (-0400) Subject: Fix: ir: copy struct/seq/array NULL fields X-Git-Tag: v2.0.0-pre1~1260 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=50fd95bf7b1bc75a3fa7c3f722c5205497daa76b Fix: ir: copy struct/seq/array NULL fields Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- 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;