From b2b635e9948980a12a2dfd8137d756b119b7c297 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 23 Feb 2016 19:24:23 -0500 Subject: [PATCH] ir: bt_ctf_event_set_packet(): check for common stream class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 63769c93..0b49abbe 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -745,6 +745,8 @@ end: int bt_ctf_event_set_packet(struct bt_ctf_event *event, struct bt_ctf_packet *packet) { + struct bt_ctf_stream_class *event_stream_class = NULL; + struct bt_ctf_stream_class *packet_stream_class = NULL; struct bt_ctf_stream *stream = NULL; int ret = 0; @@ -764,7 +766,27 @@ int bt_ctf_event_set_packet(struct bt_ctf_event *event, goto end; } } else { - /* Set the event's parent to the packet's stream */ + /* + * This event is an orphan for the moment: it's not + * associated to a stream. If this event's event + * class's stream class is the same as the packet's + * stream's stream class, then it's okay to make the + * packet's stream the parent of this event. Otherwise + * it's an error. + */ + event_stream_class = + bt_ctf_event_class_get_stream_class(event->event_class); + packet_stream_class = + bt_ctf_stream_get_class(packet->stream); + + assert(event_stream_class); + assert(packet_stream_class); + + if (event_stream_class != packet_stream_class) { + ret = -1; + goto end; + } + bt_object_set_parent(event, packet->stream); } @@ -773,6 +795,8 @@ int bt_ctf_event_set_packet(struct bt_ctf_event *event, end: BT_PUT(stream); + BT_PUT(event_stream_class); + BT_PUT(packet_stream_class); return ret; } -- 2.34.1