diff options
author | richiesams | 2013-07-07 11:45:59 -0500 |
---|---|---|
committer | richiesams | 2013-08-04 13:32:06 -0500 |
commit | ec7915bcb9d507979fa51d76de736f10b8060255 (patch) | |
tree | c87c0841a914d957dca5d73bec4d7a8b12661605 | |
parent | 00c028476513c5f41d5ac9941a7315163eeae307 (diff) | |
download | scummvm-rg350-ec7915bcb9d507979fa51d76de736f10b8060255.tar.gz scummvm-rg350-ec7915bcb9d507979fa51d76de736f10b8060255.tar.bz2 scummvm-rg350-ec7915bcb9d507979fa51d76de736f10b8060255.zip |
ZVISION: Fix eos checking in LzssReadStream
-rw-r--r-- | engines/zvision/lzss_read_stream.cpp | 14 | ||||
-rw-r--r-- | engines/zvision/lzss_read_stream.h | 1 |
2 files changed, 10 insertions, 5 deletions
diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 61b5b16393..a7cdcd9d88 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -30,7 +30,8 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, : _source(source), // It's convention to set the starting cursor position to blockSize - 16 _windowCursor(0x0FEE), - _readCursor(0) { + _readCursor(0), + _eosFlag(false) { // Clear the window to null memset(_window, 0, blockSize); @@ -104,8 +105,7 @@ void LzssReadStream::decompressAll() { } bool LzssReadStream::eos() const { - // Make sure that we've read all of the source - return _readCursor >= _destination.size() && _source->eos(); + return _eosFlag; } uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { @@ -114,15 +114,19 @@ uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { while (dataSize > _destination.size() - _readCursor) { // Check if we can read any more data from source if (_source->eos()) { + // Shorten the dataSize to what we have left and flag that we're at EOS dataSize = _destination.size() - _readCursor; + _eosFlag = true; break; } decompressBytes(blockSize); } - memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); - _readCursor += dataSize; + if (dataSize > 0) { + memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); + _readCursor += dataSize; + } return dataSize; } diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 7e6511a5a9..9ef1d6da37 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -53,6 +53,7 @@ private: char _window[blockSize]; uint16 _windowCursor; uint32 _readCursor; + bool _eosFlag; public: bool eos() const; |