From e48930c16e8912b76e41f8bc7f080bc57e703f9b Mon Sep 17 00:00:00 2001 From: David Turner Date: Sun, 21 Nov 2010 12:05:15 +0000 Subject: 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 --- engines/cruise/cell.cpp | 4 +--- engines/cruise/object.cpp | 11 +++++++++++ engines/cruise/sound.cpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'engines') 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; -- cgit v1.2.3