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
This commit is contained in:
Torbjörn Andersson 2010-09-21 17:18:32 +00:00
parent ca767d5913
commit 88e25e6f25
3 changed files with 12 additions and 12 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -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]);
}