[Scummvm-cvs-logs] SF.net SVN: scummvm:[44531] scummvm/trunk/engines/sci/engine

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Oct 2 13:04:39 CEST 2009


Revision: 44531
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44531&view=rev
Author:   fingolfin
Date:     2009-10-02 11:04:36 +0000 (Fri, 02 Oct 2009)

Log Message:
-----------
SCI: Make NULL_REG & SIGNAL_REG const; change validate_property so that its callers cannot modify NULL_REG accidentally anymore

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/engine/vm_types.h

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-10-02 07:44:55 UTC (rev 44530)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-10-02 11:04:36 UTC (rev 44531)
@@ -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 @@
 #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];

Modified: scummvm/trunk/engines/sci/engine/vm_types.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm_types.h	2009-10-02 07:44:55 UTC (rev 44530)
+++ scummvm/trunk/engines/sci/engine/vm_types.h	2009-10-02 11:04:36 UTC (rev 44531)
@@ -80,8 +80,8 @@
 	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
 


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