[Scummvm-cvs-logs] SF.net SVN: scummvm:[52377] scummvm/trunk/common

Bluddy at users.sourceforge.net Bluddy at users.sourceforge.net
Wed Aug 25 11:14:42 CEST 2010


Revision: 52377
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52377&view=rev
Author:   Bluddy
Date:     2010-08-25 09:14:41 +0000 (Wed, 25 Aug 2010)

Log Message:
-----------
COMMON: fixed EOS handling in BufferedReadStream and BufferedSeekableReadStream

EOS problem was causing Discworld to crash and zip files not to load on the PSP.

Modified Paths:
--------------
    scummvm/trunk/common/stream.cpp
    scummvm/trunk/common/stream.h

Modified: scummvm/trunk/common/stream.cpp
===================================================================
--- scummvm/trunk/common/stream.cpp	2010-08-25 09:02:43 UTC (rev 52376)
+++ scummvm/trunk/common/stream.cpp	2010-08-25 09:14:41 UTC (rev 52377)
@@ -226,6 +226,7 @@
 	: _parentStream(parentStream),
 	_disposeParentStream(disposeParentStream),
 	_pos(0),
+	_eos(false),
 	_bufSize(0),
 	_realBufSize(bufSize) {
 
@@ -255,6 +256,7 @@
 	// Check whether the data left in the buffer suffices....
 	if (dataSize > bufBytesLeft) {
 		// Nope, we need to read more data
+		_eos = true;	// we tried to read past the buffer
 
 		// First, flush the buffer, if it is non-empty
 		if (0 < bufBytesLeft) {
@@ -277,13 +279,17 @@
 		// return to the caller.
 		_bufSize = _parentStream->read(_buf, _realBufSize);
 		_pos = 0;
+		if (_bufSize)
+			_eos = false;	// we've managed to replenish our buffer
 		if (dataSize > _bufSize)
 			dataSize = _bufSize;
 	}
 
-	// Satisfy the request from the buffer
-	memcpy(dataPtr, _buf + _pos, dataSize);
-	_pos += dataSize;
+	if (dataSize) {
+		// Satisfy the request from the buffer
+		memcpy(dataPtr, _buf + _pos, dataSize);
+		_pos += dataSize;
+	}	
 	return alreadyRead + dataSize;
 }
 
@@ -297,8 +303,11 @@
 	// in the buffer only.
 	// Note: We could try to handle SEEK_END and SEEK_SET, too, but
 	// since they are rarely used, it seems not worth the effort.
+	_eos = false;	// seeking always cancels EOS
+	
 	if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) {
 		_pos += offset;
+		
 	} else {
 		// Seek was not local enough, so we reset the buffer and
 		// just seeks normally in the parent stream.
@@ -308,7 +317,7 @@
 		_parentStream->seek(offset, whence);
 	}
 
-	return true;	// FIXME: STREAM REWRITE
+	return true;
 }
 
 BufferedWriteStream::BufferedWriteStream(WriteStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)

Modified: scummvm/trunk/common/stream.h
===================================================================
--- scummvm/trunk/common/stream.h	2010-08-25 09:02:43 UTC (rev 52376)
+++ scummvm/trunk/common/stream.h	2010-08-25 09:14:41 UTC (rev 52377)
@@ -494,6 +494,7 @@
 	DisposeAfterUse::Flag _disposeParentStream;
 	byte *_buf;
 	uint32 _pos;
+	bool _eos;	// in this context it means: have we tried to read beyond the end of the buffer
 	uint32 _bufSize;
 	uint32 _realBufSize;
 	virtual void allocBuf(uint32 bufSize);	// virtual functions to allocate/deallocate the buffer
@@ -503,7 +504,7 @@
 	BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
 	virtual ~BufferedReadStream();
 
-	virtual bool eos() const { return (_pos == _bufSize) && _parentStream->eos(); }
+	virtual bool eos() const { return _eos && _parentStream->eos(); }
 	virtual bool err() const { return _parentStream->err(); }
 	virtual void clearErr() { _parentStream->clearErr(); }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list