From: Julien Desfossez Date: Wed, 17 May 2017 20:54:00 +0000 (-0400) Subject: fix: optional fields X-Git-Tag: v2.0.0-pre1~183 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=60ef553bd85cc73dbb3b935fc82ad0d870c9d4ca fix: optional fields Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index c2d5b4d1..4455dfb8 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -542,9 +542,7 @@ struct bt_ctf_field *ctf_copy_packet_context(FILE *err, packet_context = bt_ctf_packet_get_context(packet); if (!packet_context) { - fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, - __LINE__); - goto error; + goto end; } writer_stream_class = bt_ctf_stream_get_class(writer_stream); diff --git a/plugins/lttng-utils/copy.c b/plugins/lttng-utils/copy.c index 2689a703..14cc1274 100644 --- a/plugins/lttng-utils/copy.c +++ b/plugins/lttng-utils/copy.c @@ -1474,21 +1474,18 @@ struct bt_ctf_event *debug_info_copy_event(FILE *err, struct bt_ctf_event *event goto error; } + /* Optional field, so it can fail silently. */ field = bt_ctf_event_get_header(event); - if (!field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto error; - } - - ret = ctf_copy_event_header(err, event, writer_event_class, - writer_event, field); - if (ret) { - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto error; + if (field) { + ret = ctf_copy_event_header(err, event, writer_event_class, + writer_event, field); + if (ret) { + fprintf(err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } + BT_PUT(field); } - BT_PUT(field); /* Optional field, so it can fail silently. */ field = bt_ctf_event_get_stream_event_context(event); @@ -1506,8 +1503,13 @@ struct bt_ctf_event *debug_info_copy_event(FILE *err, struct bt_ctf_event *event /* Optional field, so it can fail silently. */ field = bt_ctf_event_get_event_context(event); - copy_field = bt_ctf_field_copy(field); - if (copy_field) { + if (field) { + copy_field = bt_ctf_field_copy(field); + if (!copy_field) { + fprintf(err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } ret = bt_ctf_event_set_event_context(writer_event, copy_field); if (ret < 0) { fprintf(err, "[error] %s in %s:%d\n", __func__, @@ -1515,8 +1517,8 @@ struct bt_ctf_event *debug_info_copy_event(FILE *err, struct bt_ctf_event *event goto error; } BT_PUT(copy_field); + BT_PUT(field); } - BT_PUT(field); field = bt_ctf_event_get_event_payload(event); if (!field) {