From: Mathieu Desnoyers Date: Mon, 17 Jun 2013 19:48:55 +0000 (-0400) Subject: Fix: use index, not cur_index, for SEEK_SET validation X-Git-Tag: v1.1.1~2 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=c309df1c8522c61ea9f4f108fa2d1eee3a828037;hp=5909f3321ad43ad55945ab6d3d6bdc1dd9d2cd33 Fix: use index, not cur_index, for SEEK_SET validation Fixes #551 Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index bb94e527..752b548e 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -729,14 +729,6 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence) pos->offset = 0; } else { read_next_packet: - if (pos->cur_index >= pos->packet_cycles_index->len) { - pos->offset = EOF; - return; - } - if (pos->cur_index >= pos->packet_real_index->len) { - pos->offset = EOF; - return; - } switch (whence) { case SEEK_CUR: { @@ -745,6 +737,9 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence) if (pos->offset == EOF) { return; } + assert(pos->cur_index < pos->packet_cycles_index->len); + assert(pos->cur_index < pos->packet_real_index->len); + /* For printing discarded event count */ packet_index = &g_array_index(pos->packet_cycles_index, struct packet_index, pos->cur_index); @@ -782,6 +777,10 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence) break; } case SEEK_SET: + if (index >= pos->packet_cycles_index->len) { + pos->offset = EOF; + return; + } packet_index = &g_array_index(pos->packet_cycles_index, struct packet_index, index); pos->last_events_discarded = packet_index->events_discarded;