From b34f4d90911702fc859c7b48b04e2aa19cd49b75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Dec 2014 19:03:28 -0500 Subject: [PATCH] Fix: Ensure a packet context is a structure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit bt_ctf_stream_class_set_packet_context_type was checking the current stream packet context's type instead of the one being passed. Added a test to validate that the check is done appropriately. Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/stream-class.c | 2 +- tests/lib/test_ctf_writer.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index aab7f29a..6ccaac3c 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -292,7 +292,7 @@ int bt_ctf_stream_class_set_packet_context_type( } assert(stream_class->packet_context_type); - if (bt_ctf_field_type_get_type_id(stream_class->packet_context_type) != + if (bt_ctf_field_type_get_type_id(packet_context_type) != CTF_TYPE_STRUCT) { /* A packet context must be a structure */ ret = -1; diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 9d428c24..0b72b5a3 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -1418,7 +1418,9 @@ int main(int argc, char **argv) const char *ret_string; const unsigned char *ret_uuid; unsigned char tmp_uuid[16] = { 0 }; - struct bt_ctf_field_type *packet_context_type, *packet_context_field_type; + struct bt_ctf_field_type *packet_context_type, + *packet_context_field_type, + *integer_type; struct bt_ctf_trace *trace; int ret; @@ -1675,6 +1677,11 @@ int main(int argc, char **argv) "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly"); ok(bt_ctf_stream_class_set_packet_context_type(stream_class, NULL), "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly"); + + integer_type = bt_ctf_field_type_integer_create(32); + ok(bt_ctf_stream_class_set_packet_context_type(stream_class, + integer_type) < 0, + "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure"); ret = bt_ctf_field_type_structure_add_field(packet_context_type, packet_context_field_type, "custom_field"); ok(ret == 0, "Packet context field added successfully"); @@ -1716,6 +1723,7 @@ int main(int argc, char **argv) bt_ctf_stream_put(stream1); bt_ctf_field_type_put(packet_context_type); bt_ctf_field_type_put(packet_context_field_type); + bt_ctf_field_type_put(integer_type); bt_ctf_trace_put(trace); free(metadata_string); -- 2.34.1