diff options
author | Max Horn | 2009-10-02 11:04:36 +0000 |
---|---|---|
committer | Max Horn | 2009-10-02 11:04:36 +0000 |
commit | 292640b14e42b91fca0cf4ea07920ad38095a77d (patch) | |
tree | 1314955288d57bf5425e6c527bc29e754897c9d7 /engines/sci | |
parent | 523f0b34fba6f11d3e0412c88dbdf7d415a63f36 (diff) | |
download | scummvm-rg350-292640b14e42b91fca0cf4ea07920ad38095a77d.tar.gz scummvm-rg350-292640b14e42b91fca0cf4ea07920ad38095a77d.tar.bz2 scummvm-rg350-292640b14e42b91fca0cf4ea07920ad38095a77d.zip |
SCI: Make NULL_REG & SIGNAL_REG const; change validate_property so that its callers cannot modify NULL_REG accidentally anymore
svn-id: r44531
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/vm.cpp | 13 | ||||
-rw-r--r-- | engines/sci/engine/vm_types.h | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 9e7ade1f74..36512f96ed 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -39,8 +39,8 @@ namespace Sci { -reg_t NULL_REG = {0, 0}; -reg_t SIGNAL_REG = {0, SIGNAL_OFFSET}; +const reg_t NULL_REG = {0, 0}; +const reg_t SIGNAL_REG = {0, SIGNAL_OFFSET}; //#define VM_DEBUG_SEND @@ -57,15 +57,20 @@ static bool breakpointFlag = false; // FIXME: Avoid non-const global vars #ifndef DISABLE_VALIDATIONS static reg_t &validate_property(Object *obj, int index) { + // A static dummy reg_t, which we return if obj or index turn out to be + // invalid. Note that we cannot just return NULL_REG, because client code + // may modify the value of the return reg_t. + static reg_t dummyReg = NULL_REG; + if (!obj) { debugC(2, kDebugLevelVM, "[VM] Sending to disposed object!\n"); - return NULL_REG; + return dummyReg; } if (index < 0 || (uint)index >= obj->_variables.size()) { debugC(2, kDebugLevelVM, "[VM] Invalid property #%d (out of [0..%d]) requested!\n", index, obj->_variables.size()); - return NULL_REG; + return dummyReg; } return obj->_variables[index]; diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h index 93378fe3d1..c62d0bddcb 100644 --- a/engines/sci/engine/vm_types.h +++ b/engines/sci/engine/vm_types.h @@ -80,8 +80,8 @@ static inline reg_t make_reg(SegmentId segment, uint16 offset) { return r; } -extern reg_t NULL_REG; -extern reg_t SIGNAL_REG; +extern const reg_t NULL_REG; +extern const reg_t SIGNAL_REG; } // End of namespace Sci |