mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 07:30:56 +00:00
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
This commit is contained in:
parent
f8c7243938
commit
0e7abce271
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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--) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user