Fix: Ensure a packet context is a structure
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 10 Dec 2014 00:03:28 +0000 (19:03 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 10 Dec 2014 00:06:20 +0000 (19:06 -0500)
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 <jeremie.galarneau@efficios.com>
formats/ctf/ir/stream-class.c
tests/lib/test_ctf_writer.c

index aab7f29afa08ded27f7fc266e43b728c2c2901c3..6ccaac3c41d60eb6ae308f49e7c56a9c7514139b 100644 (file)
@@ -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;
index 9d428c24bf95bf0946cb64c035821797ce9fd149..0b72b5a3babec0a8c47efe9464ff24a06f13c517 100644 (file)
@@ -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);
 
This page took 0.029145 seconds and 4 git commands to generate.