diff options
author | Torbjörn Andersson | 2010-09-21 17:18:32 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2010-09-21 17:18:32 +0000 |
commit | 88e25e6f2510cf8cee4f48d3c4d4cf6643fc5e2d (patch) | |
tree | 6b2779284b053e61d71b39de0826c9ef44cbfaaf /engines | |
parent | ca767d5913416d3fcfcec74c15e2b3e30042c22b (diff) | |
download | scummvm-rg350-88e25e6f2510cf8cee4f48d3c4d4cf6643fc5e2d.tar.gz scummvm-rg350-88e25e6f2510cf8cee4f48d3c4d4cf6643fc5e2d.tar.bz2 scummvm-rg350-88e25e6f2510cf8cee4f48d3c4d4cf6643fc5e2d.zip |
DRASCULA: Fix invalid memory access on inventory screen
When clicking outside of all inventory objects, the whichObject()
function would return 43, which is an invalid inventoryObjects[]
index. I think that's what caused it to crash for me. There are a
few other inventoryObjects[]-related changes as well.
svn-id: r52843
Diffstat (limited to 'engines')
-rw-r--r-- | engines/drascula/interface.cpp | 11 | ||||
-rw-r--r-- | engines/drascula/objects.cpp | 9 | ||||
-rw-r--r-- | engines/drascula/saveload.cpp | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/engines/drascula/interface.cpp b/engines/drascula/interface.cpp index 1495694a1b..1d17c77f83 100644 --- a/engines/drascula/interface.cpp +++ b/engines/drascula/interface.cpp @@ -120,7 +120,7 @@ void DrasculaEngine::showMenu() { x = whichObject(); strcpy(textIcon, iconName[x]); - for (n = 1; n < 43; n++) { + for (n = 1; n < ARRAYSIZE(inventoryObjects); n++) { h = inventoryObjects[n]; if (h != 0) { @@ -194,11 +194,10 @@ void DrasculaEngine::enterName() { } bool DrasculaEngine::checkMenuFlags() { - for (int n = 0; n < 43; n++) { - if (whichObject() == n) { - if (inventoryObjects[n] != 0 && checkAction(inventoryObjects[n])) - return true; - } + int n = whichObject(); + if (n != 0) { + if (inventoryObjects[n] != 0 && checkAction(inventoryObjects[n])) + return true; } return false; diff --git a/engines/drascula/objects.cpp b/engines/drascula/objects.cpp index 73aea7b7f2..2bd1014083 100644 --- a/engines/drascula/objects.cpp +++ b/engines/drascula/objects.cpp @@ -221,16 +221,17 @@ void DrasculaEngine::addObject(int obj) { * If no inventory slot is under the mouse cursor, return 0. */ int DrasculaEngine::whichObject() { - int n = 0; + int n; for (n = 1; n < ARRAYSIZE(inventoryObjects); n++) { if (mouseX > _itemLocations[n].x && mouseY > _itemLocations[n].y && mouseX < _itemLocations[n].x + OBJWIDTH && - mouseY < _itemLocations[n].y + OBJHEIGHT) - break; + mouseY < _itemLocations[n].y + OBJHEIGHT) { + return n; + } } - return n; + return 0; } void DrasculaEngine::updateVisible() { diff --git a/engines/drascula/saveload.cpp b/engines/drascula/saveload.cpp index abf17d0e8e..4aaec5ec0e 100644 --- a/engines/drascula/saveload.cpp +++ b/engines/drascula/saveload.cpp @@ -210,7 +210,7 @@ bool DrasculaEngine::loadGame(const char *gameName) { curY = sav->readSint32LE(); trackProtagonist = sav->readSint32LE(); - for (l = 1; l < 43; l++) { + for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) { inventoryObjects[l] = sav->readSint32LE(); } @@ -241,7 +241,7 @@ void DrasculaEngine::saveGame(char gameName[]) { out->writeSint32LE(curY); out->writeSint32LE(trackProtagonist); - for (l = 1; l < 43; l++) { + for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) { out->writeSint32LE(inventoryObjects[l]); } |