diff options
author | David Turner | 2010-11-21 12:05:15 +0000 |
---|---|---|
committer | David Turner | 2010-11-21 12:05:15 +0000 |
commit | e48930c16e8912b76e41f8bc7f080bc57e703f9b (patch) | |
tree | fa65a779f2c9b31e16b41b079ea21a1f63a6391a /engines/cruise | |
parent | 8045c4f87a0d2ff7bf446c74a0dfd31aa9db69e2 (diff) | |
download | scummvm-rg350-e48930c16e8912b76e41f8bc7f080bc57e703f9b.tar.gz scummvm-rg350-e48930c16e8912b76e41f8bc7f080bc57e703f9b.tar.bz2 scummvm-rg350-e48930c16e8912b76e41f8bc7f080bc57e703f9b.zip |
CRUISE: Fix Memory Accesses Errors and Leaks Reported By Valgrind
Most of these fixes are fairly simple, though the clamping of ArrayStates accesses in object.cpp _might_ cause regressions. None are obvious on basic playtest check, but the game will need a full playtest.
svn-id: r54408
Diffstat (limited to 'engines/cruise')
-rw-r--r-- | engines/cruise/cell.cpp | 4 | ||||
-rw-r--r-- | engines/cruise/object.cpp | 11 | ||||
-rw-r--r-- | engines/cruise/sound.cpp | 1 |
3 files changed, 13 insertions, 3 deletions
diff --git a/engines/cruise/cell.cpp b/engines/cruise/cell.cpp index 65cc234bda..24ae663dc7 100644 --- a/engines/cruise/cell.cpp +++ b/engines/cruise/cell.cpp @@ -65,9 +65,7 @@ cellStruct *addCell(cellStruct *pHead, int16 overlayIdx, int16 objIdx, int16 typ if (currentHead2->type != 5) { int16 lvar2; - getSingleObjectParam(currentHead2->overlay, currentHead2->idx, 2, &lvar2); - - if (lvar2 >= var) + if(getSingleObjectParam(currentHead2->overlay, currentHead2->idx, 2, &lvar2) >= 0 && lvar2 >= var) break; } diff --git a/engines/cruise/object.cpp b/engines/cruise/object.cpp index 4d2c1c2273..864491605f 100644 --- a/engines/cruise/object.cpp +++ b/engines/cruise/object.cpp @@ -79,6 +79,12 @@ int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, objectParamsQuer state = globalVars[overlayTable[overlayIdx].state + ptr->_stateTableIdx]; ptr2 = &ovlData->arrayStates[ptr->_firstStateIdx + state]; + + if (ptr->_firstStateIdx + state < 0) { + debug(0, "Invalid Negative arrayState index in getMultipleObjectParam(overlayIdx: %d, objectIdx: %d)... Forcing to 0", overlayIdx, objectIdx); + ptr2 = &ovlData->arrayStates[0]; + } + state2 = ptr2->state; break; } @@ -242,6 +248,11 @@ int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, int16 * state = globalVars[overlayTable[overlayIdx].state + ptr->_stateTableIdx]; ptr2 = &ovlData->arrayStates[ptr->_firstStateIdx + state]; + + if (ptr->_firstStateIdx + state < 0) { + debug(0, "Invalid Negative arrayState index in getSingleObjectParam(overlayIdx: %d, param2: %d, param3: %d)... Forcing to 0", overlayIdx, param2, param3); + ptr2 = &ovlData->arrayStates[0]; + } break; } case VARIABLE: { diff --git a/engines/cruise/sound.cpp b/engines/cruise/sound.cpp index 84547237cc..3cb499c6a4 100644 --- a/engines/cruise/sound.cpp +++ b/engines/cruise/sound.cpp @@ -40,6 +40,7 @@ class PCSoundDriver { public: typedef void (*UpdateCallback)(void *); + PCSoundDriver() { _upCb = NULL, _upRef = NULL, _musicVolume = 0, _sfxVolume = 0; } virtual ~PCSoundDriver() {} virtual void setupChannel(int channel, const byte *data, int instrument, int volume) = 0; |