[Scummvm-cvs-logs] SF.net SVN: scummvm:[53486] scummvm/trunk/engines/saga

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Oct 15 14:56:17 CEST 2010


Revision: 53486
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53486&view=rev
Author:   thebluegr
Date:     2010-10-15 12:56:17 +0000 (Fri, 15 Oct 2010)

Log Message:
-----------
SAGA: Added sanity checks for realloc() calls - bug report #3087852

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/saga.cpp
    scummvm/trunk/engines/saga/shorten.cpp
    scummvm/trunk/engines/saga/sprite.cpp

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2010-10-15 12:50:26 UTC (rev 53485)
+++ scummvm/trunk/engines/saga/actor.cpp	2010-10-15 12:56:17 UTC (rev 53486)
@@ -148,7 +148,11 @@
 		return;
 	}
 	_tileDirectionsAlloced = size;
-	_tileDirections = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
+	byte *tmp = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
+	if (tmp)
+		_tileDirections = tmp;
+	else
+		error("ActorData::setTileDirectionsSize(): Error while reallocating memory");
 }
 
 void ActorData::cycleWrap(int cycleLimit) {
@@ -161,7 +165,11 @@
 		return;
 	}
 	_walkStepsAlloced = size;
-	_walkStepsPoints = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
+	Point *tmp = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
+	if (tmp)
+		_walkStepsPoints = tmp;
+	else
+		error("ActorData::setWalkStepsPointsSize(): Error while reallocating memory");
 }
 
 void ActorData::addWalkStepPoint(const Point &point) {

Modified: scummvm/trunk/engines/saga/saga.cpp
===================================================================
--- scummvm/trunk/engines/saga/saga.cpp	2010-10-15 12:50:26 UTC (rev 53485)
+++ scummvm/trunk/engines/saga/saga.cpp	2010-10-15 12:56:17 UTC (rev 53486)
@@ -425,7 +425,11 @@
 		prevOffset = offset;
 		if (offset == stringsLength) {
 			stringsCount = i;
-			stringsTable.strings = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
+			const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
+			if (tmp)
+				stringsTable.strings = tmp;
+			else
+				error("SagaEngine::loadStrings() Error while reallocating memory");
 			break;
 		}
 		if (offset > stringsLength) {
@@ -433,7 +437,11 @@
 			// translation of IHNM
 			warning("SagaEngine::loadStrings wrong strings table");
 			stringsCount = i;
-			stringsTable.strings = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
+			const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
+			if (tmp)
+				stringsTable.strings = tmp;
+			else
+				error("SagaEngine::loadStrings() Error while reallocating memory");
 			break;
 		}
 		stringsTable.strings[i] = (const char *)stringsTable.stringsPointer + offset;

Modified: scummvm/trunk/engines/saga/shorten.cpp
===================================================================
--- scummvm/trunk/engines/saga/shorten.cpp	2010-10-15 12:50:26 UTC (rev 53485)
+++ scummvm/trunk/engines/saga/shorten.cpp	2010-10-15 12:56:17 UTC (rev 53486)
@@ -366,7 +366,11 @@
 						if (maxLPC < lpcNum) {
 							warning("Safeguard: maxLPC < lpcNum (should never happen)");
 							maxLPC = lpcNum;
-							lpc = (int32 *) realloc(lpc, maxLPC * 4);
+							int32 *tmp = (int32 *) realloc(lpc, maxLPC * 4);
+							if (tmp)
+								lpc = tmp;
+							else
+								error("loadShortenFromStream(): Error while reallocating memory");
 						}
 
 						for (i = 0; i < lpcNum; i++)
@@ -430,7 +434,11 @@
 
 					prevSize = size;
 					size += (blockSize * dataSize);
-					unpackedBuffer = (byte *) realloc(unpackedBuffer, size);
+					byte *tmp = (byte *) realloc(unpackedBuffer, size);
+					if (tmp)
+						unpackedBuffer = tmp;
+					else
+						error("loadShortenFromStream(): Error while reallocating memory");
 					pBuf = unpackedBuffer + prevSize;
 
 					if (flags & Audio::FLAG_16BITS) {
@@ -464,7 +472,11 @@
 				uint32 vLen = (uint32)gReader->getURice(5);
 				prevSize = size;
 				size += vLen;
-				unpackedBuffer = (byte *) realloc(unpackedBuffer, size);
+				byte *tmp = (byte *) realloc(unpackedBuffer, size);
+				if (tmp)
+					unpackedBuffer = tmp;
+				else
+					error("loadShortenFromStream(): Error while reallocating memory");
 				pBuf = unpackedBuffer + prevSize;
 
 				while (vLen--) {

Modified: scummvm/trunk/engines/saga/sprite.cpp
===================================================================
--- scummvm/trunk/engines/saga/sprite.cpp	2010-10-15 12:50:26 UTC (rev 53485)
+++ scummvm/trunk/engines/saga/sprite.cpp	2010-10-15 12:56:17 UTC (rev 53486)
@@ -115,7 +115,12 @@
 	oldSpriteCount = spriteList.spriteCount;
 	newSpriteCount = spriteList.spriteCount + spriteCount;
 
-	spriteList.infoList = (SpriteInfo *)realloc(spriteList.infoList, newSpriteCount * sizeof(*spriteList.infoList));
+	SpriteInfo *tmp = (SpriteInfo *)realloc(spriteList.infoList, newSpriteCount * sizeof(*spriteList.infoList));
+	if (tmp)
+		spriteList.infoList = tmp;
+	else
+		error("Sprite::loadList(): Error while reallocating memory");
+
 	if (spriteList.infoList == NULL) {
 		memoryError("Sprite::loadList");
 	}


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