Fix: set no field in event/packet without warnings or failing
[babeltrace.git] / lib / ctf-ir / packet.c
index fd31398dbdb9018a838a7e3a14ff1353b14adb4b..75588149d47d536de587e4f4bf459538dbd1240d 100644 (file)
@@ -72,17 +72,26 @@ int bt_ctf_packet_set_header(struct bt_ctf_packet *packet,
                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);
        assert(trace);
+       expected_header_field_type = bt_ctf_trace_get_packet_header_type(trace);
+
+       if (!header) {
+               if (expected_header_field_type) {
+                       BT_LOGW("Invalid parameter: setting no packet header but packet header field type is not NULL: "
+                               "packet-addr=%p, packet-header-ft-addr=%p",
+                               packet, expected_header_field_type);
+                       ret = -1;
+                       goto end;
+               }
+
+               goto skip_validation;
+       }
+
        header_field_type = bt_ctf_field_get_type(header);
        assert(header_field_type);
-       expected_header_field_type = bt_ctf_trace_get_packet_header_type(trace);
 
        if (bt_ctf_field_type_compare(header_field_type,
                        expected_header_field_type)) {
@@ -135,16 +144,25 @@ int bt_ctf_packet_set_context(struct bt_ctf_packet *packet,
                goto end;
        }
 
+       stream_class = bt_ctf_stream_get_class(packet->stream);
+       assert(stream_class);
+       expected_context_field_type =
+               bt_ctf_stream_class_get_packet_context_type(stream_class);
+
        if (!context) {
+               if (expected_context_field_type) {
+                       BT_LOGW("Invalid parameter: setting no packet context but packet context field type is not NULL: "
+                               "packet-addr=%p, packet-context-ft-addr=%p",
+                               packet, expected_context_field_type);
+                       ret = -1;
+                       goto end;
+               }
+
                goto skip_validation;
        }
 
-       stream_class = bt_ctf_stream_get_class(packet->stream);
-       assert(stream_class);
        context_field_type = bt_ctf_field_get_type(context);
        assert(context_field_type);
-       expected_context_field_type =
-               bt_ctf_stream_class_get_packet_context_type(stream_class);
 
        if (bt_ctf_field_type_compare(context_field_type,
                        expected_context_field_type)) {
This page took 0.023777 seconds and 4 git commands to generate.