Properly guarding Script::getOffset() and adding a reverse operation

svn-id: r41782
This commit is contained in:
Sven Hesse 2009-06-22 20:51:34 +00:00
parent 4ab4517016
commit c31b79b7c9
3 changed files with 16 additions and 2 deletions

View File

@ -94,8 +94,7 @@ byte *Expression::decodePtr(int32 n) {
switch (n >> 28) {
case kExecPtr:
ptr = _vm->_game->_script->getData();
break;
return _vm->_game->_script->getData((n & 0x0FFFFFFF));
case kInterVar:
ptr = (byte *) _vm->_inter->_variables->getAddressOff8(0);
break;

View File

@ -123,9 +123,21 @@ int32 Script::getOffset(byte *ptr) {
if (!_totData)
return -1;
if ((ptr < _totData) || (ptr >= (_totData + _totSize)))
return -1;
return ptr - _totData;
}
byte *Script::getData(int32 offset) {
if (!_totData)
return 0;
if ((offset < 0) || (((uint32) offset) >= _totSize))
return 0;
return _totData + offset;
}
byte *Script::getData() {
return _totData;
}

View File

@ -90,6 +90,9 @@ public:
/** Returns the offset the specified pointer is within the script data. */
int32 getOffset(byte *ptr);
/** Returns the data pointer to the offset. */
byte *getData(int32 offset);
/** Returns the raw data pointer. */
byte *getData();