diff options
author | Johannes Schickel | 2012-10-09 22:56:23 +0200 |
---|---|---|
committer | Johannes Schickel | 2012-10-09 23:06:25 +0200 |
commit | efe2fe7e1ffcb423d0349ee2a508f8ec0d715642 (patch) | |
tree | 76472080fab3119da98170cff29bf42e7838a991 | |
parent | 78464a42d78091ac1b54c6ae18c3a67d90fb59bf (diff) | |
download | scummvm-rg350-efe2fe7e1ffcb423d0349ee2a508f8ec0d715642.tar.gz scummvm-rg350-efe2fe7e1ffcb423d0349ee2a508f8ec0d715642.tar.bz2 scummvm-rg350-efe2fe7e1ffcb423d0349ee2a508f8ec0d715642.zip |
COMMON: Properly handle error indicator in MemoryWriteStream.
Thanks to waltervn for noticing that MemoryWriteStream::write doesn't handle
setting the error indicator properly.
-rw-r--r-- | common/memstream.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/common/memstream.h b/common/memstream.h index 69fe6ec18e..497a178ab9 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -92,13 +92,17 @@ private: byte *_ptr; const uint32 _bufSize; uint32 _pos; + bool _err; public: - MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0) {} + MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0), _err(false) {} uint32 write(const void *dataPtr, uint32 dataSize) { // Write at most as many bytes as are still available... - if (dataSize > _bufSize - _pos) + if (dataSize > _bufSize - _pos) { dataSize = _bufSize - _pos; + // We couldn't write all the data => set error indicator + _err = true; + } memcpy(_ptr, dataPtr, dataSize); _ptr += dataSize; _pos += dataSize; @@ -107,6 +111,9 @@ public: uint32 pos() const { return _pos; } uint32 size() const { return _bufSize; } + + virtual bool err() const { return _err; } + virtual void clearErr() { _err = false; } }; /** |