aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2013-01-28 17:30:57 +0100
committerJohannes Schickel2013-01-28 17:34:37 +0100
commit5bfd2f675620f69e23cefbaf8553cb341a9f992c (patch)
tree3f60e687e18168ec5d61d70f25a0a1154857c692
parentd0e9ef7dc12f5c9ff18f09536545c0e2e5e604d7 (diff)
downloadscummvm-rg350-5bfd2f675620f69e23cefbaf8553cb341a9f992c.tar.gz
scummvm-rg350-5bfd2f675620f69e23cefbaf8553cb341a9f992c.tar.bz2
scummvm-rg350-5bfd2f675620f69e23cefbaf8553cb341a9f992c.zip
COMMON: Fix successive seeks in BufferedSeekableReadStream.
This fixes the failing test case added in da8eeb9dbed2102764b3ca0697d6882bae0402cc. Thanks to wjp for his input on this.
-rw-r--r--common/stream.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index 57b1b8ba93..2851b3a320 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);
}