aboutsummaryrefslogtreecommitdiff
path: root/engines/saga
diff options
context:
space:
mode:
authorFilippos Karapetis2010-10-15 12:56:17 +0000
committerFilippos Karapetis2010-10-15 12:56:17 +0000
commitc1e47e0e60249eec5f4445de245a53f0a800e136 (patch)
tree28b5d51ddbcac7aef64cb1e7a69a18ca4359bb5a /engines/saga
parent4ccce198761e9e7da5ec495345515f7ddf922743 (diff)
downloadscummvm-rg350-c1e47e0e60249eec5f4445de245a53f0a800e136.tar.gz
scummvm-rg350-c1e47e0e60249eec5f4445de245a53f0a800e136.tar.bz2
scummvm-rg350-c1e47e0e60249eec5f4445de245a53f0a800e136.zip
SAGA: Added sanity checks for realloc() calls - bug report #3087852
svn-id: r53486
Diffstat (limited to 'engines/saga')
-rw-r--r--engines/saga/actor.cpp12
-rw-r--r--engines/saga/saga.cpp12
-rw-r--r--engines/saga/shorten.cpp18
-rw-r--r--engines/saga/sprite.cpp7
4 files changed, 41 insertions, 8 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index 8bc8025032..d44de0d75e 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -148,7 +148,11 @@ void ActorData::setTileDirectionsSize(int size, bool forceRealloc) {
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 @@ void ActorData::setWalkStepsPointsSize(int size, bool forceRealloc) {
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) {
diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp
index 1b7fa97f8d..13567f67b5 100644
--- a/engines/saga/saga.cpp
+++ b/engines/saga/saga.cpp
@@ -425,7 +425,11 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
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 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
// 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;
diff --git a/engines/saga/shorten.cpp b/engines/saga/shorten.cpp
index 2137423a5a..684b3a86bb 100644
--- a/engines/saga/shorten.cpp
+++ b/engines/saga/shorten.cpp
@@ -366,7 +366,11 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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--) {
diff --git a/engines/saga/sprite.cpp b/engines/saga/sprite.cpp
index c1a9846b47..969faae737 100644
--- a/engines/saga/sprite.cpp
+++ b/engines/saga/sprite.cpp
@@ -115,7 +115,12 @@ void Sprite::loadList(int resourceId, SpriteList &spriteList) {
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");
}