[Scummvm-cvs-logs] SF.net SVN: scummvm:[52844] scummvm/branches/branch-1-2-0/engines/drascula

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Tue Sep 21 19:20:44 CEST 2010


Revision: 52844
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52844&view=rev
Author:   eriktorbjorn
Date:     2010-09-21 17:20:44 +0000 (Tue, 21 Sep 2010)

Log Message:
-----------
DRASCULA: Fix invalid memory access on inventory screen

Backported from the trunk. Hopefully fixes a potential crash I
encountered once.

Modified Paths:
--------------
    scummvm/branches/branch-1-2-0/engines/drascula/interface.cpp
    scummvm/branches/branch-1-2-0/engines/drascula/objects.cpp
    scummvm/branches/branch-1-2-0/engines/drascula/saveload.cpp

Modified: scummvm/branches/branch-1-2-0/engines/drascula/interface.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/drascula/interface.cpp	2010-09-21 17:18:32 UTC (rev 52843)
+++ scummvm/branches/branch-1-2-0/engines/drascula/interface.cpp	2010-09-21 17:20:44 UTC (rev 52844)
@@ -120,7 +120,7 @@
 	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 @@
 }
 
 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;

Modified: scummvm/branches/branch-1-2-0/engines/drascula/objects.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/drascula/objects.cpp	2010-09-21 17:18:32 UTC (rev 52843)
+++ scummvm/branches/branch-1-2-0/engines/drascula/objects.cpp	2010-09-21 17:20:44 UTC (rev 52844)
@@ -221,16 +221,17 @@
  * 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() {

Modified: scummvm/branches/branch-1-2-0/engines/drascula/saveload.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/drascula/saveload.cpp	2010-09-21 17:18:32 UTC (rev 52843)
+++ scummvm/branches/branch-1-2-0/engines/drascula/saveload.cpp	2010-09-21 17:20:44 UTC (rev 52844)
@@ -210,7 +210,7 @@
 	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 @@
 	out->writeSint32LE(curY);
 	out->writeSint32LE(trackProtagonist);
 
-	for (l = 1; l < 43; l++) {
+	for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) {
 		out->writeSint32LE(inventoryObjects[l]);
 	}
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list