[Scummvm-cvs-logs] SF.net SVN: scummvm:[53614] scummvm/trunk/engines/saga
h00ligan at users.sourceforge.net
h00ligan at users.sourceforge.net
Tue Oct 19 17:31:07 CEST 2010
Revision: 53614
http://scummvm.svn.sourceforge.net/scummvm/?rev=53614&view=rev
Author: h00ligan
Date: 2010-10-19 15:31:07 +0000 (Tue, 19 Oct 2010)
Log Message:
-----------
SAGA: fix submit 53486 "Added sanity checks for realloc() calls - bug report #3087852". zero count realloc may return NULL as valid value
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-19 14:53:39 UTC (rev 53613)
+++ scummvm/trunk/engines/saga/actor.cpp 2010-10-19 15:31:07 UTC (rev 53614)
@@ -149,10 +149,11 @@
}
_tileDirectionsAlloced = size;
byte *tmp = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
- if (tmp)
+ if ((tmp != NULL) || (_tileDirectionsAlloced == 0)) {
_tileDirections = tmp;
- else
+ } else {
error("ActorData::setTileDirectionsSize(): Error while reallocating memory");
+ }
}
void ActorData::cycleWrap(int cycleLimit) {
@@ -166,10 +167,11 @@
}
_walkStepsAlloced = size;
Point *tmp = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
- if (tmp)
+ if ((tmp != NULL) || (_walkStepsAlloced == 0)) {
_walkStepsPoints = tmp;
- else
+ } 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-19 14:53:39 UTC (rev 53613)
+++ scummvm/trunk/engines/saga/saga.cpp 2010-10-19 15:31:07 UTC (rev 53614)
@@ -426,10 +426,11 @@
if (offset == stringsLength) {
stringsCount = i;
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
- if (tmp)
+ if ((tmp != NULL) || (stringsCount == 0)) {
stringsTable.strings = tmp;
- else
+ } else {
error("SagaEngine::loadStrings() Error while reallocating memory");
+ }
break;
}
if (offset > stringsLength) {
@@ -438,10 +439,11 @@
warning("SagaEngine::loadStrings wrong strings table");
stringsCount = i;
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
- if (tmp)
+ if ((tmp != NULL) || (stringsCount == 0)) {
stringsTable.strings = tmp;
- else
+ } 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-19 14:53:39 UTC (rev 53613)
+++ scummvm/trunk/engines/saga/shorten.cpp 2010-10-19 15:31:07 UTC (rev 53614)
@@ -367,10 +367,11 @@
warning("Safeguard: maxLPC < lpcNum (should never happen)");
maxLPC = lpcNum;
int32 *tmp = (int32 *) realloc(lpc, maxLPC * 4);
- if (tmp)
+ if ((tmp != NULL) || (maxLPC == 0)) {
lpc = tmp;
- else
+ } else {
error("loadShortenFromStream(): Error while reallocating memory");
+ }
}
for (i = 0; i < lpcNum; i++)
@@ -435,10 +436,11 @@
prevSize = size;
size += (blockSize * dataSize);
byte *tmp = (byte *) realloc(unpackedBuffer, size);
- if (tmp)
+ if ((tmp != NULL) || (size == 0)) {
unpackedBuffer = tmp;
- else
+ } else {
error("loadShortenFromStream(): Error while reallocating memory");
+ }
pBuf = unpackedBuffer + prevSize;
if (flags & Audio::FLAG_16BITS) {
@@ -473,10 +475,11 @@
prevSize = size;
size += vLen;
byte *tmp = (byte *) realloc(unpackedBuffer, size);
- if (tmp)
+ if ((tmp != NULL) || (size == 0)) {
unpackedBuffer = tmp;
- else
+ } 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-19 14:53:39 UTC (rev 53613)
+++ scummvm/trunk/engines/saga/sprite.cpp 2010-10-19 15:31:07 UTC (rev 53614)
@@ -116,13 +116,10 @@
newSpriteCount = spriteList.spriteCount + spriteCount;
SpriteInfo *tmp = (SpriteInfo *)realloc(spriteList.infoList, newSpriteCount * sizeof(*spriteList.infoList));
- if (tmp)
+ if ((tmp != NULL) || (newSpriteCount == 0)) {
spriteList.infoList = tmp;
- else
+ } else {
error("Sprite::loadList(): Error while reallocating memory");
-
- if (spriteList.infoList == NULL) {
- memoryError("Sprite::loadList");
}
spriteList.spriteCount = newSpriteCount;
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