Fix support for empty streams
[babeltrace.git] / formats / ctf / ctf.c
index f9f9e47fde8947812b40034077431f04584a7000..27c03cfa8c2e23d211f2a5ed16fe5582f2f6bc66 100644 (file)
@@ -127,8 +127,16 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
        uint64_t id = 0;
        int ret;
 
+       /* We need to check for EOF here for empty files. */
+       if (unlikely(pos->offset == EOF))
+               return EOF;
+
        ctf_pos_get_event(pos);
 
+       /*
+        * This is the EOF check after we've advanced the position in
+        * ctf_pos_get_event.
+        */
        if (unlikely(pos->offset == EOF))
                return EOF;
        assert(pos->offset < pos->content_size);
@@ -408,6 +416,7 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                        /* empty packet */
                        pos->offset = index->data_offset;
                        offset = 0;
+                       whence = SEEK_CUR;
                        goto read_next_packet;
                } else {
                        pos->offset = EOF;
This page took 0.023305 seconds and 4 git commands to generate.