diff options
author | Julien | 2011-06-05 05:22:40 +0800 |
---|---|---|
committer | Julien | 2011-06-23 15:11:37 +0800 |
commit | 367605d774df038166b14044a5f5ce935f244519 (patch) | |
tree | 051917f11e3d00cffc4d0deb2e9415b7e69903be | |
parent | 5aa1877beffa71a2cc712a85b74a788e22a924e2 (diff) | |
download | scummvm-rg350-367605d774df038166b14044a5f5ce935f244519.tar.gz scummvm-rg350-367605d774df038166b14044a5f5ce935f244519.tar.bz2 scummvm-rg350-367605d774df038166b14044a5f5ce935f244519.zip |
TSAGE: Allocate resource decoding buffer on the heap
-rw-r--r-- | engines/toon/path.cpp | 24 | ||||
-rw-r--r-- | engines/tsage/resources.cpp | 11 |
2 files changed, 30 insertions, 5 deletions
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index dde7be07d0..43a134e39b 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -342,8 +342,15 @@ next: curX = destx; curY = desty; - int32 retPathX[4096]; - int32 retPathY[4096]; + int32 *retPathX = (int32 *)malloc(4096 * sizeof(int32)); + int32 *retPathY = (int32 *)malloc(4096 * sizeof(int32)); + if (!retPathX || !retPathY) { + free(retPathX); + free(retPathY); + + error("[PathFinding::findPath] Cannot allocate pathfinding buffers"); + } + int32 numpath = 0; retPathX[numpath] = curX; @@ -377,8 +384,12 @@ next: } } - if (bestX < 0 || bestY < 0) + if (bestX < 0 || bestY < 0) { + free(retPathX); + free(retPathY); + return 0; + } retPathX[numpath] = bestX; retPathY[numpath] = bestY; @@ -389,6 +400,10 @@ next: memcpy(_tempPathX, retPathX, sizeof(int32) * numpath); memcpy(_tempPathY, retPathY, sizeof(int32) * numpath); + + free(retPathX); + free(retPathY); + return true; } @@ -396,6 +411,9 @@ next: curY = bestY; } + free(retPathX); + free(retPathY); + return false; } diff --git a/engines/tsage/resources.cpp b/engines/tsage/resources.cpp index d24c564a1f..e6a561f3a7 100644 --- a/engines/tsage/resources.cpp +++ b/engines/tsage/resources.cpp @@ -237,8 +237,13 @@ byte *TLib::getResource(uint16 id, bool suppressErrors) { uint16 ctrCurrent = 0x102, ctrMax = 0x200; uint16 word_48050 = 0, currentToken = 0, word_48054 =0; byte byte_49068 = 0, byte_49069 = 0; - DecodeReference table[0x1000]; - for (int i = 0; i < 0x1000; ++i) { + + const uint tableSize = 0x1000; + DecodeReference *table = (DecodeReference *)malloc(tableSize * sizeof(DecodeReference)); + if (!table) + error("[TLib::getResource] Cannot allocate table buffer"); + + for (int i = 0; i < tableSize; ++i) { table[i].vByte = table[i].vWord = 0; } Common::Stack<uint16> tokenList; @@ -302,6 +307,8 @@ byte *TLib::getResource(uint16 id, bool suppressErrors) { } } + free(table); + assert(bytesWritten == re->uncompressedSize); delete compStream; return dataOut; |