[Scummvm-cvs-logs] SF.net SVN: scummvm: [32463] tools/trunk/kyra_ins.cpp

athrxx at users.sourceforge.net athrxx at users.sourceforge.net
Sun Jun 1 15:19:57 CEST 2008


Revision: 32463
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32463&view=rev
Author:   athrxx
Date:     2008-06-01 06:19:55 -0700 (Sun, 01 Jun 2008)

Log Message:
-----------
- (hopefully) fix valgrind warning for installer file decompression

Modified Paths:
--------------
    tools/trunk/kyra_ins.cpp

Modified: tools/trunk/kyra_ins.cpp
===================================================================
--- tools/trunk/kyra_ins.cpp	2008-06-01 13:19:45 UTC (rev 32462)
+++ tools/trunk/kyra_ins.cpp	2008-06-01 13:19:55 UTC (rev 32463)
@@ -24,7 +24,7 @@
 
 class FileExpanderSource {
 public:
-	FileExpanderSource(const uint8 *data) : _dataPtr(data), _bitsLeft(8), _key(0), _index(0) {}
+	FileExpanderSource(const uint8 *data, int dataSize) : _dataPtr(data), _endofBuffer(data + dataSize), _bitsLeft(8), _key(0), _index(0) {}
 	~FileExpanderSource() {}
 
 	void advSrcRefresh();
@@ -40,6 +40,7 @@
 
 private:
 	const uint8 *_dataPtr;
+	const uint8 *_endofBuffer;
 	uint16 _key;
 	int8 _bitsLeft;
 	uint8 _index;
@@ -48,7 +49,8 @@
 void FileExpanderSource::advSrcBitsBy1() {
 	_key >>= 1;		
 	if (!--_bitsLeft) {
-		_key = ((*_dataPtr++) << 8 ) | (_key & 0xff);
+		if (_dataPtr < _endofBuffer)
+			_key = ((*_dataPtr++) << 8 ) | (_key & 0xff);
 		_bitsLeft = 8;
 	}
 }
@@ -60,7 +62,8 @@
 		_key >>= (_index + _bitsLeft);
 		_index = -_bitsLeft;
 		_bitsLeft = 8 - _index;
-		_key = (*_dataPtr++ << 8) | (_key & 0xff);
+		if (_dataPtr < _endofBuffer)
+			_key = (*_dataPtr++ << 8) | (_key & 0xff);
 	}
 	_key >>= _index;
 }
@@ -109,7 +112,8 @@
 
 void FileExpanderSource::advSrcRefresh() {
 	_key = READ_LE_UINT16(_dataPtr);
-	_dataPtr += 2;		
+	if (_dataPtr < _endofBuffer - 1)
+		_dataPtr += 2;
 	_bitsLeft = 8;
 }
 
@@ -166,7 +170,7 @@
 	bool needrefresh = true;
 	bool postprocess = false;
 
-	_src = new FileExpanderSource(src);
+	_src = new FileExpanderSource(src, compressedSize);
 
 	while (d < dst + outsize) {
 


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