field-types.c: check that we don't add self FT to struct/var FT
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 24 Nov 2016 21:44:01 +0000 (16:44 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/field-types.c
tests/lib/test_ctf_writer.c

index 49919ca2fe008796111955d76655c2f72f733d2a..7f324c9a47b5c25f5a107e8e4bbf2bdf92e27392 100644 (file)
@@ -1410,9 +1410,14 @@ int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *type,
        int ret = 0;
        struct bt_ctf_field_type_structure *structure;
 
+       /*
+        * TODO: check that `field_type` does not contain `type`,
+        *       recursively.
+        */
        if (!type || !field_type || type->frozen ||
                bt_ctf_validate_identifier(field_name) ||
-               (type->declaration->id != BT_CTF_TYPE_ID_STRUCT)) {
+               (type->declaration->id != BT_CTF_TYPE_ID_STRUCT) ||
+               type == field_type) {
                ret = -1;
                goto end;
        }
@@ -1615,9 +1620,14 @@ int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type,
        struct bt_ctf_field_type_variant *variant;
        GQuark field_name_quark = g_quark_from_string(field_name);
 
+       /*
+        * TODO: check that `field_type` does not contain `type`,
+        *       recursively.
+        */
        if (!type || !field_type || type->frozen ||
                bt_ctf_validate_identifier(field_name) ||
-               (type->declaration->id != BT_CTF_TYPE_ID_VARIANT)) {
+               (type->declaration->id != BT_CTF_TYPE_ID_VARIANT) ||
+               type == field_type) {
                ret = -1;
                goto end;
        }
index 04e9d996ba209300d6e39c96ef5f7a39070e60e9..b6b029c59cdbee313112395205df2ed4e65cba12 100644 (file)
@@ -59,7 +59,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 604
+#define NR_TESTS 605
 
 static int64_t current_time = 42;
 
@@ -786,6 +786,8 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class,
        ok(bt_ctf_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH,
                "bt_ctf_field_type_array_get_length returns the correct length");
 
+       ok(bt_ctf_field_type_structure_add_field(inner_structure_type,
+               inner_structure_type, "yes"), "Cannot add self to structure");
        ok(!bt_ctf_field_type_structure_add_field(inner_structure_type,
                uint_35_type, "seq_len"), "Add seq_len field to inner structure");
        ok(!bt_ctf_field_type_structure_add_field(inner_structure_type,
This page took 0.027823 seconds and 4 git commands to generate.