aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorKari Salminen2008-08-09 20:50:10 +0000
committerKari Salminen2008-08-09 20:50:10 +0000
commit09119829549c13c06aa5af80ca01197eb8ce7cda (patch)
treef14702cbdc935a58cb899870e0deb285dd80cca7 /engines
parentc60565e108a5e541b00f0f4b6ab1e7dfa476945c (diff)
downloadscummvm-rg350-09119829549c13c06aa5af80ca01197eb8ce7cda.tar.gz
scummvm-rg350-09119829549c13c06aa5af80ca01197eb8ce7cda.tar.bz2
scummvm-rg350-09119829549c13c06aa5af80ca01197eb8ce7cda.zip
Converted objectTable from a plain array to a Common::Array. Should help to catch out of bounds access errors that may cause memory corruption.
svn-id: r33725
Diffstat (limited to 'engines')
-rw-r--r--engines/cine/cine.cpp7
-rw-r--r--engines/cine/gfx.cpp6
-rw-r--r--engines/cine/object.cpp9
-rw-r--r--engines/cine/object.h15
-rw-r--r--engines/cine/various.cpp11
5 files changed, 30 insertions, 18 deletions
diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp
index 4726e47732..900f1678db 100644
--- a/engines/cine/cine.cpp
+++ b/engines/cine/cine.cpp
@@ -124,6 +124,10 @@ int CineEngine::modifyGameSpeed(int speedChange) {
}
void CineEngine::initialize() {
+ // Resize object table to its correct size and reset all its elements
+ objectTable.resize(NUM_MAX_OBJECT);
+ resetObjectTable();
+
_timerDelayMultiplier = 12; // Set default speed
setupOpcodes();
@@ -160,8 +164,7 @@ void CineEngine::initialize() {
freeAnimDataTable();
overlayList.clear();
messageTable.clear();
-
- memset(objectTable, 0, sizeof(objectTable));
+ resetObjectTable();
var8 = 0;
diff --git a/engines/cine/gfx.cpp b/engines/cine/gfx.cpp
index 0266a605e2..1da4a91d7f 100644
--- a/engines/cine/gfx.cpp
+++ b/engines/cine/gfx.cpp
@@ -471,7 +471,7 @@ void FWRenderer::renderOverlay(const Common::List<overlay>::iterator &it) {
// bitmap
case 4:
assert(it->objIdx < NUM_MAX_OBJECT);
- obj = objectTable + it->objIdx;
+ obj = &objectTable[it->objIdx];
if (obj->frame < 0) {
return;
@@ -1107,7 +1107,7 @@ void OSRenderer::renderOverlay(const Common::List<overlay>::iterator &it) {
case 20:
assert(it->objIdx < NUM_MAX_OBJECT);
var5 = it->x; // A global variable updated here!
- obj = objectTable + it->objIdx;
+ obj = &objectTable[it->objIdx];
sprite = animDataTable + obj->frame;
if (obj->frame < 0 || it->x < 0 || it->x > 8 || !_bgTable[it->x].bg || sprite->_bpp != 1) {
@@ -1128,7 +1128,7 @@ void OSRenderer::renderOverlay(const Common::List<overlay>::iterator &it) {
case 22: {
// TODO: Check it this implementation really works correctly (Some things might be wrong, needs testing).
assert(it->objIdx < NUM_MAX_OBJECT);
- obj = objectTable + it->objIdx;
+ obj = &objectTable[it->objIdx];
byte color = obj->part & 0x0F;
int width = obj->frame;
int height = obj->costume;
diff --git a/engines/cine/object.cpp b/engines/cine/object.cpp
index c02e01c8ce..9781975f7c 100644
--- a/engines/cine/object.cpp
+++ b/engines/cine/object.cpp
@@ -35,9 +35,16 @@
namespace Cine {
-objectStruct objectTable[NUM_MAX_OBJECT];
+Common::Array<objectStruct> objectTable;
Common::List<overlay> overlayList;
+/*! \brief Resets all elements in the object table. */
+void resetObjectTable() {
+ for (Common::Array<objectStruct>::iterator it = objectTable.begin(); it != objectTable.end(); it++) {
+ it->clear();
+ }
+}
+
void loadObject(char *pObjectName) {
uint16 numEntry;
uint16 entrySize;
diff --git a/engines/cine/object.h b/engines/cine/object.h
index 7ad65eb75f..3bf6cdcc42 100644
--- a/engines/cine/object.h
+++ b/engines/cine/object.h
@@ -38,6 +38,17 @@ struct objectStruct {
int16 costume;
char name[20];
uint16 part;
+
+ /*! \brief Sets all member variables to zero. */
+ void clear() {
+ this->x = 0;
+ this->y = 0;
+ this->mask = 0;
+ this->frame = 0;
+ this->costume = 0;
+ memset(this->name, 0, sizeof(this->name));
+ this->part = 0;
+ }
};
struct overlay {
@@ -52,10 +63,10 @@ struct overlay {
#define NUM_MAX_OBJECT 255
#define NUM_MAX_VAR 255
-extern objectStruct objectTable[NUM_MAX_OBJECT];
-
+extern Common::Array<objectStruct> objectTable;
extern Common::List<overlay> overlayList;
+void resetObjectTable();
void loadObject(char *pObjectName);
void setupObject(byte objIdx, uint16 param1, uint16 param2, uint16 param3, uint16 param4);
void modifyObjectParam(byte objIdx, byte paramIdx, int16 newValue);
diff --git a/engines/cine/various.cpp b/engines/cine/various.cpp
index 01039a30a4..c2ead98d13 100644
--- a/engines/cine/various.cpp
+++ b/engines/cine/various.cpp
@@ -618,16 +618,7 @@ void CineEngine::resetEngine() {
relTable.clear();
scriptTable.clear();
messageTable.clear();
-
- for (int i = 0; i < NUM_MAX_OBJECT; i++) {
- objectTable[i].x = 0;
- objectTable[i].y = 0;
- objectTable[i].part = 0;
- objectTable[i].name[0] = 0;
- objectTable[i].frame = 0;
- objectTable[i].mask = 0;
- objectTable[i].costume = 0;
- }
+ resetObjectTable();
globalVars.reset();