aboutsummaryrefslogtreecommitdiff
path: root/sword2/function.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-11-10 07:52:15 +0000
committerTorbjörn Andersson2003-11-10 07:52:15 +0000
commit3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4 (patch)
treec09b3c0e43525ea8d355fa6d364a20cee9be6252 /sword2/function.cpp
parent439bc8364d248293c1ba7b1d92d2b00b4a6fa609 (diff)
downloadscummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.tar.gz
scummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.tar.bz2
scummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.zip
The script engine frequently needs to pass pointers to various structures
etc. to the different opcodes. Until now it has done so by casting the pointer to an int32 (opcode parameters are represented as arrays of int32) and then the opcode function casts it back to whatever pointer it needs. At least in C there is no guarantee that a pointer can be represented as an integer type (though apparently C99 may define such a type), so this has struck me as unsafe ever since I first noticed it. However, since all such pointers appear to point to the memory block owned by the memory manager, we can easily convert them to integers by treating them as offsets into the memory block. So that's what I have done. I hope I caught all the occurences in the opcode functions, or we're going to have some pretty interesting regressions on our hands... svn-id: r11241
Diffstat (limited to 'sword2/function.cpp')
-rw-r--r--sword2/function.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/sword2/function.cpp b/sword2/function.cpp
index f2c6b3ff04..ae31b0d911 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -148,7 +148,7 @@ int32 Logic::fnPause(int32 *params) {
// NB. Pause-value of 0 causes script to continue, 1 causes a 1-cycle
// quit, 2 gives 2 cycles, etc.
- Object_logic *ob_logic = (Object_logic *) params[0];
+ Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
if (ob_logic->looping == 0) {
// start the pause
@@ -177,7 +177,7 @@ int32 Logic::fnRandomPause(int32 *params) {
// 1 minimum number of game-cycles to pause
// 2 maximum number of game-cycles to pause
- Object_logic *ob_logic = (Object_logic *) params[0];
+ Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
int32 pars[2];
if (ob_logic->looping == 0) {
@@ -202,7 +202,7 @@ int32 Logic::fnPassGraph(int32 *params) {
// params: 0 pointer to a graphic structure (might not need this?)
- memcpy(&_vm->_engineGraph, (uint8 *) params[0], sizeof(Object_graphic));
+ memcpy(&_vm->_engineGraph, memory->intToPtr(params[0]), sizeof(Object_graphic));
// makes no odds
return IR_CONT;
@@ -218,7 +218,7 @@ int32 Logic::fnPassMega(int32 *params) {
// params: 0 pointer to a mega structure
- memcpy(&_vm->_engineMega, (uint8 *) params[0], sizeof(Object_mega));
+ memcpy(&_vm->_engineMega, memory->intToPtr(params[0]), sizeof(Object_mega));
// makes no odds
return IR_CONT;
@@ -233,7 +233,7 @@ int32 Logic::fnSetValue(int32 *params) {
// params: 0 pointer to object's mega structure
// 1 value to set it to
- Object_mega *ob_mega = (Object_mega *) params[0];
+ Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]);
ob_mega->megaset_res = params[1];