aboutsummaryrefslogtreecommitdiff
path: root/common/stream.cpp
diff options
context:
space:
mode:
authorMax Horn2008-07-30 07:39:41 +0000
committerMax Horn2008-07-30 07:39:41 +0000
commit1e2988b7f75adc471e3dc39aa42eb99e33727023 (patch)
treef42f6a504e47b513ac7d1bb70895d1db5c6479cf /common/stream.cpp
parent8bdbbaf413d61cacbe62d11195842c93be786a18 (diff)
downloadscummvm-rg350-1e2988b7f75adc471e3dc39aa42eb99e33727023.tar.gz
scummvm-rg350-1e2988b7f75adc471e3dc39aa42eb99e33727023.tar.bz2
scummvm-rg350-1e2988b7f75adc471e3dc39aa42eb99e33727023.zip
Changed BufferedReadStream to not permanently decrease its buffer size at the end of a stream (this would fail when using BufferedSeekableReadStream and then seeking back from the end); this also fixes a bug which let you seek back beyond the start of a stream (not that we currently support that in other streams)
svn-id: r33436
Diffstat (limited to 'common/stream.cpp')
-rw-r--r--common/stream.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index d068e2fc1e..e06cc28415 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -244,14 +244,16 @@ void SeekableSubReadStream::seek(int32 offset, int whence) {
BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream)
: _parentStream(parentStream),
- _bufSize(bufSize),
- _disposeParentStream(disposeParentStream) {
+ _disposeParentStream(disposeParentStream),
+ _pos(0),
+ _bufSize(0),
+ _realBufSize(bufSize) {
assert(parentStream);
- _buf = new byte[_bufSize];
+ _buf = new byte[bufSize];
assert(_buf);
- _pos = _bufSize = bufSize;
}
+
BufferedReadStream::~BufferedReadStream() {
if (_disposeParentStream)
delete _parentStream;
@@ -281,18 +283,14 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) {
return alreadyRead + _parentStream->read(dataPtr, dataSize);
// Refill the buffer.
- uint32 bytesRead = _parentStream->read(_buf, _bufSize);
- _pos = 0;
-
// If we didn't read as many bytes as requested, the reason
// is EOF or an error. In that case we truncate the buffer
// size, as well as the number of bytes we are going to
// return to the caller.
- if (_bufSize > bytesRead) {
- _bufSize = bytesRead;
- if (dataSize > bytesRead)
- dataSize = bytesRead;
- }
+ _bufSize = _parentStream->read(_buf, _realBufSize);
+ _pos = 0;
+ if (dataSize > _bufSize)
+ dataSize = _bufSize;
}
// Satisfy the request from the buffer