Fix: disallow re-using same event ID in same stream
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-generate-io-struct.c
index 664d0af13f2c60faec9e63621c32e6e07cb7037c..98169457ffab32825580f57a0d79b7e8663a399d 100644 (file)
@@ -268,6 +268,14 @@ struct ctf_stream_declaration *trace_stream_lookup(struct ctf_trace *trace, uint
        return g_ptr_array_index(trace->streams, stream_id);
 }
 
+static
+struct ctf_event_declaration *stream_event_lookup(struct ctf_stream_declaration *stream, uint64_t event_id)
+{
+       if (stream->events_by_id->len <= event_id)
+               return NULL;
+       return g_ptr_array_index(stream->events_by_id, event_id);
+}
+
 static
 struct ctf_clock *trace_clock_lookup(struct ctf_trace *trace, GQuark clock_name)
 {
@@ -1319,6 +1327,11 @@ struct bt_declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
                                return NULL;
                        }
                        size = right->u.unary_expression.u.unsigned_constant;
+                       if (!size) {
+                               fprintf(fd, "[error] %s: integer size: expecting non-zero constant\n",
+                                       __func__);
+                               return NULL;
+                       }
                        has_size = 1;
                } else if (!strcmp(left->u.unary_expression.u.string, "align")) {
                        if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
@@ -1880,6 +1893,13 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
                fprintf(fd, "[error] %s: missing id field in event declaration\n", __func__);
                goto error;
        }
+       /* Disallow re-using the same event ID in the same stream */
+       if (stream_event_lookup(event->stream, event->id)) {
+               ret = -EPERM;
+               fprintf(fd, "[error] %s: event ID %" PRIu64 " used more than once in stream %" PRIu64 "\n",
+                       __func__, event->id, event->stream_id);
+               goto error;
+       }
        if (event->stream->events_by_id->len <= event->id)
                g_ptr_array_set_size(event->stream->events_by_id, event->id + 1);
        g_ptr_array_index(event->stream->events_by_id, event->id) = event;
@@ -2399,6 +2419,7 @@ int ctf_clock_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                                goto error;
                        }
                        clock->absolute = ret;
+                       ret = 0;
                } else {
                        fprintf(fd, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__, left);
                }
This page took 0.023404 seconds and 4 git commands to generate.