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>
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 */
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;
+
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;
}
/* 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)) {
+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)
{