aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-04-05 11:13:08 +0200
committerMax Horn2011-04-05 15:18:08 +0200
commita12dada82249cb713e2a9162b26ad3207127726c (patch)
tree1f9835408f15e7bc1dd49414e442d1024c7e1f70
parent0adfe7296664b2bd7edaf9b1e351c069631addc4 (diff)
downloadscummvm-rg350-a12dada82249cb713e2a9162b26ad3207127726c.tar.gz
scummvm-rg350-a12dada82249cb713e2a9162b26ad3207127726c.tar.bz2
scummvm-rg350-a12dada82249cb713e2a9162b26ad3207127726c.zip
SCUMM: Fix off-by-one mistakes in out-of-bounds checks; name some constants
-rw-r--r--engines/scumm/script.cpp14
-rw-r--r--engines/scumm/script.h21
2 files changed, 24 insertions, 11 deletions
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index a76461f579..c481fb8a4e 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -319,6 +319,9 @@ void ScummEngine::runScriptNested(int script) {
updateScriptPtr();
+ if (vm.numNestedScripts >= kMaxScriptNesting)
+ error("Too many nested scripts");
+
nest = &vm.nest[vm.numNestedScripts];
if (_currentScript == 0xFF) {
@@ -334,9 +337,6 @@ void ScummEngine::runScriptNested(int script) {
vm.numNestedScripts++;
- if (vm.numNestedScripts > ARRAYSIZE(vm.nest))
- error("Too many nested scripts");
-
_currentScript = script;
getScriptBaseAddress();
resetScriptPointer();
@@ -1284,7 +1284,7 @@ void ScummEngine::beginCutscene(int *args) {
vm.slot[scr].cutsceneOverride++;
++vm.cutSceneStackPointer;
- if (vm.cutSceneStackPointer > ARRAYSIZE(vm.cutSceneData))
+ if (vm.cutSceneStackPointer >= kMaxCutsceneNum)
error("Cutscene stack overflow");
vm.cutSceneData[vm.cutSceneStackPointer] = args[0];
@@ -1325,7 +1325,7 @@ void ScummEngine::endCutscene() {
void ScummEngine::abortCutscene() {
const int idx = vm.cutSceneStackPointer;
- assert(0 <= idx && idx < 5);
+ assert(0 <= idx && idx < kMaxCutsceneNum);
uint32 offs = vm.cutScenePtr[idx];
if (offs) {
@@ -1344,7 +1344,7 @@ void ScummEngine::abortCutscene() {
void ScummEngine::beginOverride() {
const int idx = vm.cutSceneStackPointer;
- assert(0 <= idx && idx < 5);
+ assert(0 <= idx && idx < kMaxCutsceneNum);
vm.cutScenePtr[idx] = _scriptPointer - _scriptOrgPointer;
vm.cutSceneScript[idx] = _currentScript;
@@ -1361,7 +1361,7 @@ void ScummEngine::beginOverride() {
void ScummEngine::endOverride() {
const int idx = vm.cutSceneStackPointer;
- assert(0 <= idx && idx < 5);
+ assert(0 <= idx && idx < kMaxCutsceneNum);
vm.cutScenePtr[idx] = 0;
vm.cutSceneScript[idx] = 0;
diff --git a/engines/scumm/script.h b/engines/scumm/script.h
index dbfa2630e5..39d5d802b4 100644
--- a/engines/scumm/script.h
+++ b/engines/scumm/script.h
@@ -98,16 +98,29 @@ struct NestedScript {
uint8 slot;
};
+enum {
+ /**
+ * The maximal number of cutscenes that can be active
+ * in parallel (i.e. nested).
+ */
+ kMaxCutsceneNum = 5,
+
+ /**
+ * The maximal 'nesting' level for scripts.
+ */
+ kMaxScriptNesting = 15
+};
+
struct VirtualMachineState {
- uint32 cutScenePtr[5];
- byte cutSceneScript[5];
- int16 cutSceneData[5];
+ uint32 cutScenePtr[kMaxCutsceneNum];
+ byte cutSceneScript[kMaxCutsceneNum];
+ int16 cutSceneData[kMaxCutsceneNum];
int16 cutSceneScriptIndex;
byte cutSceneStackPointer;
ScriptSlot slot[NUM_SCRIPT_SLOT];
int32 localvar[NUM_SCRIPT_SLOT][26];
- NestedScript nest[15];
+ NestedScript nest[kMaxScriptNesting];
byte numNestedScripts;
};