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
4 changed files with 23 additions and 19 deletions
|
@ -149,10 +149,11 @@ void ActorData::setTileDirectionsSize(int size, bool forceRealloc) {
|
||||||
}
|
}
|
||||||
_tileDirectionsAlloced = size;
|
_tileDirectionsAlloced = size;
|
||||||
byte *tmp = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
|
byte *tmp = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
|
||||||
if (tmp)
|
if ((tmp != NULL) || (_tileDirectionsAlloced == 0)) {
|
||||||
_tileDirections = tmp;
|
_tileDirections = tmp;
|
||||||
else
|
} else {
|
||||||
error("ActorData::setTileDirectionsSize(): Error while reallocating memory");
|
error("ActorData::setTileDirectionsSize(): Error while reallocating memory");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActorData::cycleWrap(int cycleLimit) {
|
void ActorData::cycleWrap(int cycleLimit) {
|
||||||
|
@ -166,10 +167,11 @@ void ActorData::setWalkStepsPointsSize(int size, bool forceRealloc) {
|
||||||
}
|
}
|
||||||
_walkStepsAlloced = size;
|
_walkStepsAlloced = size;
|
||||||
Point *tmp = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
|
Point *tmp = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
|
||||||
if (tmp)
|
if ((tmp != NULL) || (_walkStepsAlloced == 0)) {
|
||||||
_walkStepsPoints = tmp;
|
_walkStepsPoints = tmp;
|
||||||
else
|
} else {
|
||||||
error("ActorData::setWalkStepsPointsSize(): Error while reallocating memory");
|
error("ActorData::setWalkStepsPointsSize(): Error while reallocating memory");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActorData::addWalkStepPoint(const Point &point) {
|
void ActorData::addWalkStepPoint(const Point &point) {
|
||||||
|
|
|
@ -426,10 +426,11 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
|
||||||
if (offset == stringsLength) {
|
if (offset == stringsLength) {
|
||||||
stringsCount = i;
|
stringsCount = i;
|
||||||
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
||||||
if (tmp)
|
if ((tmp != NULL) || (stringsCount == 0)) {
|
||||||
stringsTable.strings = tmp;
|
stringsTable.strings = tmp;
|
||||||
else
|
} else {
|
||||||
error("SagaEngine::loadStrings() Error while reallocating memory");
|
error("SagaEngine::loadStrings() Error while reallocating memory");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (offset > stringsLength) {
|
if (offset > stringsLength) {
|
||||||
|
@ -438,10 +439,11 @@ void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPoin
|
||||||
warning("SagaEngine::loadStrings wrong strings table");
|
warning("SagaEngine::loadStrings wrong strings table");
|
||||||
stringsCount = i;
|
stringsCount = i;
|
||||||
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
const char **tmp = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
||||||
if (tmp)
|
if ((tmp != NULL) || (stringsCount == 0)) {
|
||||||
stringsTable.strings = tmp;
|
stringsTable.strings = tmp;
|
||||||
else
|
} else {
|
||||||
error("SagaEngine::loadStrings() Error while reallocating memory");
|
error("SagaEngine::loadStrings() Error while reallocating memory");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stringsTable.strings[i] = (const char *)stringsTable.stringsPointer + offset;
|
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)");
|
warning("Safeguard: maxLPC < lpcNum (should never happen)");
|
||||||
maxLPC = lpcNum;
|
maxLPC = lpcNum;
|
||||||
int32 *tmp = (int32 *) realloc(lpc, maxLPC * 4);
|
int32 *tmp = (int32 *) realloc(lpc, maxLPC * 4);
|
||||||
if (tmp)
|
if ((tmp != NULL) || (maxLPC == 0)) {
|
||||||
lpc = tmp;
|
lpc = tmp;
|
||||||
else
|
} else {
|
||||||
error("loadShortenFromStream(): Error while reallocating memory");
|
error("loadShortenFromStream(): Error while reallocating memory");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < lpcNum; i++)
|
for (i = 0; i < lpcNum; i++)
|
||||||
|
@ -435,10 +436,11 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
|
||||||
prevSize = size;
|
prevSize = size;
|
||||||
size += (blockSize * dataSize);
|
size += (blockSize * dataSize);
|
||||||
byte *tmp = (byte *) realloc(unpackedBuffer, size);
|
byte *tmp = (byte *) realloc(unpackedBuffer, size);
|
||||||
if (tmp)
|
if ((tmp != NULL) || (size == 0)) {
|
||||||
unpackedBuffer = tmp;
|
unpackedBuffer = tmp;
|
||||||
else
|
} else {
|
||||||
error("loadShortenFromStream(): Error while reallocating memory");
|
error("loadShortenFromStream(): Error while reallocating memory");
|
||||||
|
}
|
||||||
pBuf = unpackedBuffer + prevSize;
|
pBuf = unpackedBuffer + prevSize;
|
||||||
|
|
||||||
if (flags & Audio::FLAG_16BITS) {
|
if (flags & Audio::FLAG_16BITS) {
|
||||||
|
@ -473,10 +475,11 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
|
||||||
prevSize = size;
|
prevSize = size;
|
||||||
size += vLen;
|
size += vLen;
|
||||||
byte *tmp = (byte *) realloc(unpackedBuffer, size);
|
byte *tmp = (byte *) realloc(unpackedBuffer, size);
|
||||||
if (tmp)
|
if ((tmp != NULL) || (size == 0)) {
|
||||||
unpackedBuffer = tmp;
|
unpackedBuffer = tmp;
|
||||||
else
|
} else {
|
||||||
error("loadShortenFromStream(): Error while reallocating memory");
|
error("loadShortenFromStream(): Error while reallocating memory");
|
||||||
|
}
|
||||||
pBuf = unpackedBuffer + prevSize;
|
pBuf = unpackedBuffer + prevSize;
|
||||||
|
|
||||||
while (vLen--) {
|
while (vLen--) {
|
||||||
|
|
|
@ -116,13 +116,10 @@ void Sprite::loadList(int resourceId, SpriteList &spriteList) {
|
||||||
newSpriteCount = spriteList.spriteCount + spriteCount;
|
newSpriteCount = spriteList.spriteCount + spriteCount;
|
||||||
|
|
||||||
SpriteInfo *tmp = (SpriteInfo *)realloc(spriteList.infoList, newSpriteCount * sizeof(*spriteList.infoList));
|
SpriteInfo *tmp = (SpriteInfo *)realloc(spriteList.infoList, newSpriteCount * sizeof(*spriteList.infoList));
|
||||||
if (tmp)
|
if ((tmp != NULL) || (newSpriteCount == 0)) {
|
||||||
spriteList.infoList = tmp;
|
spriteList.infoList = tmp;
|
||||||
else
|
} else {
|
||||||
error("Sprite::loadList(): Error while reallocating memory");
|
error("Sprite::loadList(): Error while reallocating memory");
|
||||||
|
|
||||||
if (spriteList.infoList == NULL) {
|
|
||||||
memoryError("Sprite::loadList");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteList.spriteCount = newSpriteCount;
|
spriteList.spriteCount = newSpriteCount;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue