ir: bt_ctf_event_set_clock_value(): validate clock value's class
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Apr 2017 23:28:53 +0000 (19:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:40 +0000 (12:57 -0400)
On bt_ctf_event_set_clock_value(): validate that the clock class of a
clock value is part of the event's trace object.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/ctf-ir/trace-internal.h
lib/ctf-ir/event.c
lib/ctf-ir/trace.c

index 38c89e7b3c8d15756961c7a576fcef093354c587..d332a581049d9cf798af161c3597ca4be5a60a8d 100644 (file)
@@ -85,4 +85,8 @@ BT_HIDDEN
 int bt_ctf_trace_object_modification(struct bt_ctf_object *object,
                void *trace_ptr);
 
 int bt_ctf_trace_object_modification(struct bt_ctf_object *object,
                void *trace_ptr);
 
+BT_HIDDEN
+bool bt_ctf_trace_has_clock_class(struct bt_ctf_trace *trace,
+               struct bt_ctf_clock_class *clock_class);
+
 #endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */
 #endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */
index 6d878fd757c93c3fc8d170d21f6e3bdc118c6d63..5fd732de331b14f613f170467e0c171962324d3a 100644 (file)
@@ -586,15 +586,34 @@ int bt_ctf_event_set_clock_value(struct bt_ctf_event *event,
                struct bt_ctf_clock_value *value)
 {
        int ret = 0;
                struct bt_ctf_clock_value *value)
 {
        int ret = 0;
+       struct bt_ctf_trace *trace;
+       struct bt_ctf_stream_class *stream_class;
+       struct bt_ctf_event_class *event_class;
+       struct bt_ctf_clock_class *clock_class = NULL;
 
        if (!event || !value || event->frozen) {
                ret = -1;
                goto end;
        }
 
 
        if (!event || !value || event->frozen) {
                ret = -1;
                goto end;
        }
 
-       g_hash_table_insert(event->clock_values,
-               bt_ctf_clock_value_get_class(value), bt_get(value));
+       clock_class = bt_ctf_clock_value_get_class(value);
+       event_class = bt_ctf_event_borrow_event_class(event);
+       assert(event_class);
+       stream_class = bt_ctf_event_class_borrow_stream_class(event_class);
+       assert(stream_class);
+       trace = bt_ctf_stream_class_borrow_trace(stream_class);
+       assert(trace);
+
+       if (!bt_ctf_trace_has_clock_class(trace, clock_class)) {
+               ret = -1;
+               goto end;
+       }
+
+       g_hash_table_insert(event->clock_values, clock_class, bt_get(value));
+       clock_class = NULL;
+
 end:
 end:
+       bt_put(clock_class);
        return ret;
 }
 
        return ret;
 }
 
index 1b239fa3f457f1c3f5dbb30e72791bbb6bcfe153..999270882fbe7a42221e23686f5d4625e2013825 100644 (file)
@@ -389,7 +389,6 @@ int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
                struct bt_ctf_clock_class *clock_class)
 {
        int ret = 0;
                struct bt_ctf_clock_class *clock_class)
 {
        int ret = 0;
-       struct search_query query = { .value = clock_class, .found = 0 };
 
        if (!trace || !bt_ctf_clock_class_is_valid(clock_class)) {
                ret = -1;
 
        if (!trace || !bt_ctf_clock_class_is_valid(clock_class)) {
                ret = -1;
@@ -397,8 +396,7 @@ int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
        }
 
        /* Check for duplicate clock classes */
        }
 
        /* Check for duplicate clock classes */
-       g_ptr_array_foreach(trace->clocks, value_exists, &query);
-       if (query.found) {
+       if (bt_ctf_trace_has_clock_class(trace, clock_class)) {
                ret = -1;
                goto end;
        }
                ret = -1;
                goto end;
        }
@@ -805,6 +803,19 @@ end:
        return clock_class;
 }
 
        return clock_class;
 }
 
+BT_HIDDEN
+bool bt_ctf_trace_has_clock_class(struct bt_ctf_trace *trace,
+               struct bt_ctf_clock_class *clock_class)
+{
+       struct search_query query = { .value = clock_class, .found = 0 };
+
+       assert(trace);
+       assert(clock_class);
+
+       g_ptr_array_foreach(trace->clocks, value_exists, &query);
+       return query.found;
+}
+
 BT_HIDDEN
 const char *get_byte_order_string(enum bt_ctf_byte_order byte_order)
 {
 BT_HIDDEN
 const char *get_byte_order_string(enum bt_ctf_byte_order byte_order)
 {
This page took 0.02894 seconds and 4 git commands to generate.