[Scummvm-cvs-logs] SF.net SVN: scummvm:[33725] scummvm/trunk/engines/cine
buddha_ at users.sourceforge.net
buddha_ at users.sourceforge.net
Sat Aug 9 22:50:13 CEST 2008
Revision: 33725
http://scummvm.svn.sourceforge.net/scummvm/?rev=33725&view=rev
Author: buddha_
Date: 2008-08-09 20:50:10 +0000 (Sat, 09 Aug 2008)
Log Message:
-----------
Converted objectTable from a plain array to a Common::Array. Should help to catch out of bounds access errors that may cause memory corruption.
Modified Paths:
--------------
scummvm/trunk/engines/cine/cine.cpp
scummvm/trunk/engines/cine/gfx.cpp
scummvm/trunk/engines/cine/object.cpp
scummvm/trunk/engines/cine/object.h
scummvm/trunk/engines/cine/various.cpp
Modified: scummvm/trunk/engines/cine/cine.cpp
===================================================================
--- scummvm/trunk/engines/cine/cine.cpp 2008-08-09 20:04:39 UTC (rev 33724)
+++ scummvm/trunk/engines/cine/cine.cpp 2008-08-09 20:50:10 UTC (rev 33725)
@@ -124,6 +124,10 @@
}
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,9 +164,8 @@
freeAnimDataTable();
overlayList.clear();
messageTable.clear();
+ resetObjectTable();
- memset(objectTable, 0, sizeof(objectTable));
-
var8 = 0;
var2 = var3 = var4 = var5 = 0;
Modified: scummvm/trunk/engines/cine/gfx.cpp
===================================================================
--- scummvm/trunk/engines/cine/gfx.cpp 2008-08-09 20:04:39 UTC (rev 33724)
+++ scummvm/trunk/engines/cine/gfx.cpp 2008-08-09 20:50:10 UTC (rev 33725)
@@ -471,7 +471,7 @@
// 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 @@
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 @@
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;
Modified: scummvm/trunk/engines/cine/object.cpp
===================================================================
--- scummvm/trunk/engines/cine/object.cpp 2008-08-09 20:04:39 UTC (rev 33724)
+++ scummvm/trunk/engines/cine/object.cpp 2008-08-09 20:50:10 UTC (rev 33725)
@@ -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;
Modified: scummvm/trunk/engines/cine/object.h
===================================================================
--- scummvm/trunk/engines/cine/object.h 2008-08-09 20:04:39 UTC (rev 33724)
+++ scummvm/trunk/engines/cine/object.h 2008-08-09 20:50:10 UTC (rev 33725)
@@ -38,6 +38,17 @@
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 @@
#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);
Modified: scummvm/trunk/engines/cine/various.cpp
===================================================================
--- scummvm/trunk/engines/cine/various.cpp 2008-08-09 20:04:39 UTC (rev 33724)
+++ scummvm/trunk/engines/cine/various.cpp 2008-08-09 20:50:10 UTC (rev 33725)
@@ -618,17 +618,8 @@
relTable.clear();
scriptTable.clear();
messageTable.clear();
+ resetObjectTable();
- 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;
- }
-
globalVars.reset();
var2 = var3 = var4 = var5 = 0;
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