ZVISION: Fix eos checking in LzssReadStream

This commit is contained in:
richiesams
2013-08-04 13:32:06 -05:00
parent 00c0284765
commit ec7915bcb9
2 changed files with 10 additions and 5 deletions
+9 -5
View File
@@ -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;
}
+1
View File
@@ -53,6 +53,7 @@ private:
char _window[blockSize];
uint16 _windowCursor;
uint32 _readCursor;
bool _eosFlag;
public:
bool eos() const;