Skip to content

Commit

Permalink
COMMON: Fix successive seeks in BufferedSeekableReadStream.
Browse files Browse the repository at this point in the history
This fixes the failing test case added in
da8eeb9.

Thanks to wjp for his input on this.
  • Loading branch information
Johannes Schickel committed Jan 28, 2013
1 parent d0e9ef7 commit 5bfd2f6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion common/stream.cpp
Expand Up @@ -393,7 +393,14 @@ bool BufferedSeekableReadStream::seek(int32 offset, int whence) {
// just seek normally in the parent stream.
if (whence == SEEK_CUR)
offset -= (_bufSize - _pos);
_pos = _bufSize;
// We invalidate the buffer here. This assures that successive seeks
// do not have the chance to incorrectly think they seeked back into
// the buffer.
// Note: This does not take full advantage of the buffer. But it is
// a simple way to prevent nasty errors. It would be possible to take
// full advantage of the buffer by saving its actual start position.
// This seems not worth the effort for this seemingly uncommon use.
_pos = _bufSize = 0;
_parentStream->seek(offset, whence);
}

Expand Down

0 comments on commit 5bfd2f6

Please sign in to comment.