aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kurushin2010-10-19 15:31:07 +0000
committerAndrew Kurushin2010-10-19 15:31:07 +0000
commit0e7abce271c218faa6ae19059207fed5d61b0ef8 (patch)
treee2df8762901d0d45dba9f6d1a6c88c817b44228f
parentf8c72439383c6ea6324d03fa4c9e067a33af2235 (diff)
downloadscummvm-rg350-0e7abce271c218faa6ae19059207fed5d61b0ef8.tar.gz
scummvm-rg350-0e7abce271c218faa6ae19059207fed5d61b0ef8.tar.bz2
scummvm-rg350-0e7abce271c218faa6ae19059207fed5d61b0ef8.zip
SAGA: fix submit 53486 "Added sanity checks for realloc() calls - bug report #3087852". zero count realloc may return NULL as valid value
svn-id: r53614
-rw-r--r--engines/saga/actor.cpp10
-rw-r--r--engines/saga/saga.cpp10
-rw-r--r--engines/saga/shorten.cpp15
-rw-r--r--engines/saga/sprite.cpp7
4 files changed, 23 insertions, 19 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index d44de0d75e..6e6707c2b5 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -149,10 +149,11 @@ void ActorData::setTileDirectionsSize(int size, bool forceRealloc) {
}
_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 @@ void ActorData::setWalkStepsPointsSize(int size, bool forceRealloc) {
}
_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) {
diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp
index 13567f67b5..1643ecfa17 100644
--- a/engines/saga/saga.cpp
+++ b/engines/saga/saga.cpp
@@ -426,10 +426,11 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
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 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
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;
diff --git a/engines/saga/shorten.cpp b/engines/saga/shorten.cpp
index 684b3a86bb..8353c7dbad 100644
--- a/engines/saga/shorten.cpp
+++ b/engines/saga/shorten.cpp
@@ -367,10 +367,11 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
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--) {
diff --git a/engines/saga/sprite.cpp b/engines/saga/sprite.cpp
index 969faae737..a62f7c57eb 100644
--- a/engines/saga/sprite.cpp
+++ b/engines/saga/sprite.cpp
@@ -116,13 +116,10 @@ void Sprite::loadList(int resourceId, SpriteList &spriteList) {
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;