SCUMM: Use correct array size when calling initializeLocals()

The initializeLocals() function assumes that it can copy 25
elements when being provided an array of values. But this array
was frequently a lot smaller than that. I've introduced a constant
for the number of locals (though VirtualMachineState has one more
for some reason), and fixed the array sizes in a number of places.

CID 1003951, 1003952, 1003953, 1003955, 1003956, 1003959, 1003960,
1003961, 1003963, 100394, 1003965
This commit is contained in:
Torbjörn Andersson 2013-04-30 22:26:51 +02:00
parent 6936f830ea
commit 2284aba719
4 changed files with 24 additions and 21 deletions

View file

@ -138,10 +138,10 @@ void ScummEngine::runObjectScript(int object, int entry, bool freezeResistant, b
void ScummEngine::initializeLocals(int slot, int *vars) {
int i;
if (!vars) {
for (i = 0; i < 25; i++)
for (i = 0; i < NUM_SCRIPT_LOCALS; i++)
vm.localvar[slot][i] = 0;
} else {
for (i = 0; i < 25; i++)
for (i = 0; i < NUM_SCRIPT_LOCALS; i++)
vm.localvar[slot][i] = vars[i];
}
}
@ -755,7 +755,7 @@ void ScummEngine::stopObjectCode() {
}
void ScummEngine::runInventoryScript(int i) {
int args[24];
int args[NUM_SCRIPT_LOCALS];
memset(args, 0, sizeof(args));
args[0] = i;
if (VAR(VAR_INVENTORY_SCRIPT)) {
@ -1060,7 +1060,7 @@ void ScummEngine::doSentence(int verb, int objectA, int objectB) {
void ScummEngine::checkAndRunSentenceScript() {
int i;
int localParamList[24];
int localParamList[NUM_SCRIPT_LOCALS];
const ScriptSlot *ss;
int sentenceScript;
@ -1308,7 +1308,7 @@ void ScummEngine_v0::runSentenceScript() {
}
void ScummEngine_v2::runInputScript(int clickArea, int val, int mode) {
int args[24];
int args[NUM_SCRIPT_LOCALS];
int verbScript;
verbScript = 4;
@ -1332,7 +1332,7 @@ void ScummEngine_v2::runInputScript(int clickArea, int val, int mode) {
}
void ScummEngine::runInputScript(int clickArea, int val, int mode) {
int args[24];
int args[NUM_SCRIPT_LOCALS];
int verbScript;
verbScript = VAR(VAR_VERB_SCRIPT);
@ -1490,7 +1490,7 @@ void ScummEngine::beginCutscene(int *args) {
void ScummEngine::endCutscene() {
ScriptSlot *ss = &vm.slot[_currentScript];
int args[16];
int args[NUM_SCRIPT_LOCALS];
if (ss->cutsceneOverride > 0) // Only terminate if active
ss->cutsceneOverride--;