From: Jérémie Galarneau Date: Fri, 25 Nov 2016 20:12:02 +0000 (-0500) Subject: Allow NULL bt_ctf_packet_set_header and bt_ctf_packet_set_context X-Git-Tag: v2.0.0-pre1~652 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=03bc92d45c22dd239e9b13e376c3173b8f560944 Allow NULL bt_ctf_packet_set_header and bt_ctf_packet_set_context Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/packet.c b/formats/ctf/ir/packet.c index 59e193fc..6236e00b 100644 --- a/formats/ctf/ir/packet.c +++ b/formats/ctf/ir/packet.c @@ -56,11 +56,15 @@ int bt_ctf_packet_set_header(struct bt_ctf_packet *packet, struct bt_ctf_field_type *header_field_type = NULL; struct bt_ctf_field_type *expected_header_field_type = NULL; - if (!packet || !header || packet->frozen) { + if (!packet || packet->frozen) { ret = -1; goto end; } + if (!header) { + goto skip_validation; + } + stream_class = bt_ctf_stream_get_class(packet->stream); assert(stream_class); trace = bt_ctf_stream_class_get_trace(stream_class); @@ -75,6 +79,7 @@ int bt_ctf_packet_set_header(struct bt_ctf_packet *packet, goto end; } +skip_validation: bt_put(packet->header); packet->header = bt_get(header); @@ -101,11 +106,15 @@ int bt_ctf_packet_set_context(struct bt_ctf_packet *packet, struct bt_ctf_field_type *context_field_type = NULL; struct bt_ctf_field_type *expected_context_field_type = NULL; - if (!packet || !context || packet->frozen) { + if (!packet || packet->frozen) { ret = -1; goto end; } + if (!context) { + goto skip_validation; + } + stream_class = bt_ctf_stream_get_class(packet->stream); assert(stream_class); context_field_type = bt_ctf_field_get_type(context); @@ -119,6 +128,7 @@ int bt_ctf_packet_set_context(struct bt_ctf_packet *packet, goto end; } +skip_validation: bt_put(packet->context); packet->context = bt_get(context); @@ -177,14 +187,14 @@ struct bt_ctf_packet *bt_ctf_packet_create( bt_object_init(packet, bt_ctf_packet_destroy); packet->stream = bt_get(stream); packet->header = bt_ctf_field_create(trace->packet_header_type); - if (!packet->header) { + if (!packet->header && trace->packet_header_type) { BT_PUT(packet); goto end; } packet->context = bt_ctf_field_create( stream->stream_class->packet_context_type); - if (!packet->context) { + if (!packet->context && stream->stream_class->packet_context_type) { BT_PUT(packet); goto end; }