diff options
-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; |