From: Jérémie Galarneau Date: Wed, 10 Dec 2014 00:03:28 +0000 (-0500) Subject: Fix: Ensure a packet context is a structure X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=b34f4d90911702fc859c7b48b04e2aa19cd49b75;p=deliverable%2Fbabeltrace.git Fix: Ensure a packet context is a structure 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 --- diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index aab7f29af..6ccaac3c4 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 9d428c24b..0b72b5a3b 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);