Duplicate variant field name check
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-generate-io-struct.c
index f137f6d32e9d90efe8dcd828435bc20a9450391c..bdb5c68d6cfaa45ec3395fc7ad408eb23ff9792a 100644 (file)
@@ -431,6 +431,13 @@ int ctf_struct_type_declarators_visit(FILE *fd, int depth,
                        fprintf(fd, "[error] %s: unable to find struct field declaration type\n", __func__);
                        return -EINVAL;
                }
+
+               /* Check if field with same name already exists */
+               if (struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
+                       fprintf(fd, "[error] %s: duplicate field %s in struct\n", __func__, g_quark_to_string(field_name));
+                       return -EINVAL;
+               }
+
                struct_declaration_add_field(struct_declaration,
                                             g_quark_to_string(field_name),
                                             field_declaration);
@@ -461,6 +468,13 @@ int ctf_variant_type_declarators_visit(FILE *fd, int depth,
                        fprintf(fd, "[error] %s: unable to find variant field declaration type\n", __func__);
                        return -EINVAL;
                }
+
+               if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
+                       fprintf(fd, "[error] %s: duplicate field %s in variant\n", __func__, g_quark_to_string(field_name));
+                       return -EINVAL;
+               }
+
+
                untagged_variant_declaration_add_field(untagged_variant_declaration,
                                              g_quark_to_string(field_name),
                                              field_declaration);
@@ -1747,7 +1761,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
        stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
        stream->events_by_id = g_ptr_array_new();
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
-       stream->files = g_ptr_array_new();
+       stream->streams = g_ptr_array_new();
        if (node) {
                cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
                        ret = ctf_stream_declaration_visit(fd, depth + 1, iter, stream, trace);
@@ -1785,7 +1799,7 @@ error:
                declaration_unref(&stream->event_context_decl->p);
        if (stream->packet_context_decl)
                declaration_unref(&stream->packet_context_decl->p);
-       g_ptr_array_free(stream->files, TRUE);
+       g_ptr_array_free(stream->streams, TRUE);
        g_ptr_array_free(stream->events_by_id, TRUE);
        g_hash_table_destroy(stream->event_quark_to_id);
        free_declaration_scope(stream->declaration_scope);
This page took 0.024347 seconds and 4 git commands to generate.