From 5bfd2f675620f69e23cefbaf8553cb341a9f992c Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 28 Jan 2013 17:30:57 +0100 Subject: [PATCH] COMMON: Fix successive seeks in BufferedSeekableReadStream. This fixes the failing test case added in da8eeb9dbed2102764b3ca0697d6882bae0402cc. Thanks to wjp for his input on this. --- common/stream.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/stream.cpp b/common/stream.cpp index 57b1b8ba937..2851b3a3209 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -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); }