From 03bc92d45c22dd239e9b13e376c3173b8f560944 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 25 Nov 2016 15:12:02 -0500 Subject: [PATCH] Allow NULL bt_ctf_packet_set_header and bt_ctf_packet_set_context MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/packet.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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; } -- 2.34.1