[Scummvm-cvs-logs] SF.net SVN: scummvm:[48961] scummvm/trunk/engines/sword2/interpreter.cpp
eriktorbjorn at users.sourceforge.net
eriktorbjorn at users.sourceforge.net
Thu May 6 21:00:40 CEST 2010
Revision: 48961
http://scummvm.svn.sourceforge.net/scummvm/?rev=48961&view=rev
Author: eriktorbjorn
Date: 2010-05-06 19:00:39 +0000 (Thu, 06 May 2010)
Log Message:
-----------
Make sure that all the parameters to an mcode command are initialised. This
fixes one Valgrind warning mentioned in bug #2976008 ("BS2: Game lockup in
British Museum"), though I don't have high hopes that they are related.
Modified Paths:
--------------
scummvm/trunk/engines/sword2/interpreter.cpp
Modified: scummvm/trunk/engines/sword2/interpreter.cpp
===================================================================
--- scummvm/trunk/engines/sword2/interpreter.cpp 2010-05-06 18:54:56 UTC (rev 48960)
+++ scummvm/trunk/engines/sword2/interpreter.cpp 2010-05-06 19:00:39 UTC (rev 48961)
@@ -243,6 +243,8 @@
// and then updated the object hub myself.
int Logic::runScript2(byte *scriptData, byte *objectData, byte *offsetPtr) {
+ int i;
+
// Interestingly, unlike our BASS engine the stack is a local variable.
// I don't know whether or not this is relevant to the working of the
// BS2 engine.
@@ -284,11 +286,9 @@
scriptNumber = offset;
debug(8, "Starting script %d from %d", scriptNumber, ip);
} else {
- uint i;
-
ip = offset;
- for (i = 1; i < noScripts; i++) {
+ for (i = 1; i < (int)noScripts; i++) {
if (READ_LE_UINT32(offsetTable + 4 * i) >= ip)
break;
}
@@ -331,8 +331,8 @@
int32 codeLen = READ_LE_UINT32(checksumBlock + 4);
int32 checksum = 0;
- for (int i = 0; i < codeLen; i++)
- checksum += (unsigned char) code[i];
+ for (i = 0; i < codeLen; i++)
+ checksum += (unsigned char)code[i];
if (checksum != (int32)READ_LE_UINT32(checksumBlock + 8)) {
debug(1, "Checksum error in object %s", header.name);
@@ -348,7 +348,6 @@
int savedStartOfMcode = 0; // For saving start of mcode commands
while (runningScript) {
- int i;
int32 a, b;
int curCommand, parameter, value; // Command and parameter variables
int retVal;
@@ -614,9 +613,20 @@
// amount to adjust stack by (no of parameters)
Read8ip(value);
debug(9, "CP_CALL_MCODE: '%s', %d", _opcodes[parameter].desc, value);
+
+ // The scripts do not always call the mcode command
+ // with as many parameters as it can accept. To keep
+ // things predictable, initialise the remaining
+ // parameters to 0.
+
+ for (i = STACK_SIZE - 1; i >= value; i--) {
+ opcodeParams[i] = 0;
+ }
+
while (--value >= 0) {
opcodeParams[value] = stack.pop();
}
+
retVal = (this->*_opcodes[parameter].proc)(opcodeParams);
switch (retVal & 7) {
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