aboutsummaryrefslogtreecommitdiff
path: root/engines/saga/shorten.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/saga/shorten.cpp')
-rw-r--r--engines/saga/shorten.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/engines/saga/shorten.cpp b/engines/saga/shorten.cpp
index 2137423a5a..592c2d0618 100644
--- a/engines/saga/shorten.cpp
+++ b/engines/saga/shorten.cpp
@@ -239,7 +239,7 @@ byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, by
return NULL;
}
- // Get block size
+ // Get block size
if (version > 0) {
blockSize = gReader->getUint32((int) (log((double) DEFAULT_BLOCK_SIZE) / M_LN2));
maxLPC = gReader->getUint32(2);
@@ -366,7 +366,12 @@ 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 != NULL) || (maxLPC == 0)) {
+ lpc = tmp;
+ } else {
+ error("loadShortenFromStream(): Error while reallocating memory");
+ }
}
for (i = 0; i < lpcNum; i++)
@@ -430,7 +435,12 @@ 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 != NULL) || (size == 0)) {
+ unpackedBuffer = tmp;
+ } else {
+ error("loadShortenFromStream(): Error while reallocating memory");
+ }
pBuf = unpackedBuffer + prevSize;
if (flags & Audio::FLAG_16BITS) {
@@ -464,7 +474,12 @@ 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 != NULL) || (size == 0)) {
+ unpackedBuffer = tmp;
+ } else {
+ error("loadShortenFromStream(): Error while reallocating memory");
+ }
pBuf = unpackedBuffer + prevSize;
while (vLen--) {