Allow NULL bt_ctf_packet_set_header and bt_ctf_packet_set_context
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 25 Nov 2016 20:12:02 +0000 (15:12 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/packet.c

index 59e193fc9a12a7b76dd25e67ae4434efa9b37c71..6236e00bdb5e7cbc4837feed6f76b4d88151532c 100644 (file)
@@ -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;
        }
This page took 0.025757 seconds and 4 git commands to generate.