[Scummvm-cvs-logs] SF.net SVN: scummvm:[51733] scummvm/trunk/engines/sci/graphics/ports.cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Aug 4 14:41:00 CEST 2010


Revision: 51733
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51733&view=rev
Author:   thebluegr
Date:     2010-08-04 12:41:00 +0000 (Wed, 04 Aug 2010)

Log Message:
-----------
SCI: Fixed an off-by-one error in GfxPorts::getPortById() and moved the error checking code outside the function. Also fixed script bug #3039305 - "HOYLE4: segfault"

Modified Paths:
--------------
    scummvm/trunk/engines/sci/graphics/ports.cpp

Modified: scummvm/trunk/engines/sci/graphics/ports.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/ports.cpp	2010-08-04 12:18:38 UTC (rev 51732)
+++ scummvm/trunk/engines/sci/graphics/ports.cpp	2010-08-04 12:41:00 UTC (rev 51733)
@@ -179,8 +179,18 @@
 	case 0xFFFF:
 		setPort(_menuPort);
 		break;
-	default:
-		setPort(getPortById(portId));
+	default: {
+		Port *newPort = getPortById(portId);
+		if (newPort)
+			setPort(newPort);
+		else {
+			if (g_sci->getGameId() == GID_HOYLE4 && portId == 3) {
+				// Hoyle 4 attempts to set invalid port ID 3 when closing the options dialog (bug #3039305)
+			} else {
+				error("GfxPorts::kernelSetActive was requested to set invalid port id %d", portId);
+			}
+		}
+	}
 	};
 }
 
@@ -218,7 +228,10 @@
 
 void GfxPorts::kernelDisposeWindow(uint16 windowId, bool reanimate) {
 	Window *wnd = (Window *)getPortById(windowId);
-	removeWindow(wnd, reanimate);
+	if (wnd)
+		removeWindow(wnd, reanimate);
+	else
+		error("GfxPorts::kernelDisposeWindow: Request to dispose invalid port id %d", windowId);
 }
 
 int16 GfxPorts::isFrontWindow(Window *pWnd) {
@@ -415,7 +428,7 @@
 		_paint16->kernelGraphRedrawBox(pWnd->restoreRect);
 	_windowList.remove(pWnd);
 	setPort(_windowList.back());
-	_windowsById[pWnd->id] = 0;
+	_windowsById[pWnd->id] = NULL;
 	delete pWnd;
 }
 
@@ -444,9 +457,7 @@
 }
 
 Port *GfxPorts::getPortById(uint16 id) {
-	if (id > _windowsById.size())
-		error("getPortById() received invalid id");
-	return _windowsById[id];
+	return (id < _windowsById.size()) ? _windowsById[id] : NULL;
 }
 
 Port *GfxPorts::setPort(Port *newPort) {


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