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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun May 30 18:14:32 CEST 2010


Revision: 49327
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49327&view=rev
Author:   thebluegr
Date:     2010-05-30 16:14:31 +0000 (Sun, 30 May 2010)

Log Message:
-----------
Limit access to the _bufSize, _scriptSize and _heapSize members of the Script class

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/features.cpp
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kscripts.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/script.cpp
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.cpp
    scummvm/trunk/engines/sci/engine/segment.h
    scummvm/trunk/engines/sci/engine/vm.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/console.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -1245,7 +1245,7 @@
 
 	case SEG_TYPE_SCRIPT: {
 		Script *scr = (Script *)mobj;
-		DebugPrintf("script.%03d locked by %d, bufsize=%d (%x)\n", scr->_nr, scr->getLockers(), (uint)scr->_bufSize, (uint)scr->_bufSize);
+		DebugPrintf("script.%03d locked by %d, bufsize=%d (%x)\n", scr->_nr, scr->getLockers(), (uint)scr->getBufSize(), (uint)scr->getBufSize());
 		if (scr->_exportTable)
 			DebugPrintf("  Exports: %4d at %d\n", scr->_numExports, (int)(((const byte *)scr->_exportTable) - ((const byte *)scr->_buf)));
 		else

Modified: scummvm/trunk/engines/sci/engine/features.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/features.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/features.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -87,7 +87,7 @@
 		opcode = extOpcode >> 1;
 
 		// Check for end of script
-		if (opcode == op_ret || offset >= script->_bufSize)
+		if (opcode == op_ret || offset >= script->getBufSize())
 			break;
 
 		// The play method of the Sound object pushes the DoSound command
@@ -223,7 +223,7 @@
 		opcode = extOpcode >> 1;
 
 		// Check for end of script
-		if (opcode == op_ret || offset >= script->_bufSize)
+		if (opcode == op_ret || offset >= script->getBufSize())
 			break;
 
 		if (opcode == op_lofsa || opcode == op_lofss) {
@@ -231,13 +231,13 @@
 			uint16 lofs = opparams[0];
 
 			// Check for going out of bounds when interpreting as abs/rel
-			if (lofs >= script->_bufSize)
+			if (lofs >= script->getBufSize())
 				_lofsType = SCI_VERSION_0_EARLY;
 
 			if ((signed)offset + (int16)lofs < 0)
 				_lofsType = SCI_VERSION_1_MIDDLE;
 
-			if ((signed)offset + (int16)lofs >= (signed)script->_bufSize)
+			if ((signed)offset + (int16)lofs >= (signed)script->getBufSize())
 				_lofsType = SCI_VERSION_1_MIDDLE;
 
 			if (_lofsType != SCI_VERSION_NONE)
@@ -309,7 +309,7 @@
 		opcode = extOpcode >> 1;
 
 		// Check for end of script
-		if (opcode == op_ret || offset >= script->_bufSize)
+		if (opcode == op_ret || offset >= script->getBufSize())
 			break;
 
 		if (opcode == op_callk) {
@@ -412,7 +412,7 @@
 		opcode = extOpcode >> 1;
 
 		// Check for end of script
-		if (opcode == op_ret || offset >= script->_bufSize)
+		if (opcode == op_ret || offset >= script->getBufSize())
 			break;
 
 		if (opcode == op_callk) {
@@ -465,7 +465,7 @@
 		opcode = extOpcode >> 1;
 
 		// Check for end of script
-		if (opcode == op_ret || offset >= script->_bufSize)
+		if (opcode == op_ret || offset >= script->getBufSize())
 			break;
 
 		if (opcode == op_callk) {

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -628,7 +628,7 @@
 
 	switch (mobj->getType()) {
 	case SEG_TYPE_SCRIPT:
-		if (reg.offset <= (*(Script *)mobj)._bufSize &&
+		if (reg.offset <= (*(Script *)mobj).getBufSize() &&
 			reg.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET &&
 		    RAW_IS_OBJECT((*(Script *)mobj)._buf + reg.offset)) {
 			return ((Script *)mobj)->getObject(reg.offset) ? KSIG_OBJECT : KSIG_REF;

Modified: scummvm/trunk/engines/sci/engine/kscripts.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kscripts.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/kscripts.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -208,7 +208,7 @@
 
 	// Point to the heap for SCI1.1+ games
 	if (getSciVersion() >= SCI_VERSION_1_1)
-		address += scr->_scriptSize;
+		address += scr->getScriptSize();
 
 	return make_reg(scriptSeg, address);
 }

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -758,22 +758,22 @@
 }
 
 static void load_script(EngineState *s, Script *scr) {
-	scr->_buf = (byte *)malloc(scr->_bufSize);
+	scr->_buf = (byte *)malloc(scr->getBufSize());
 	assert(scr->_buf);
 
 	Resource *script = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, scr->_nr), 0);
 	assert(script != 0);
 
-	assert(scr->_bufSize >= script->size);
+	assert(scr->getBufSize() >= script->size);
 	memcpy(scr->_buf, script->data, script->size);
 
 	if (getSciVersion() >= SCI_VERSION_1_1) {
 		Resource *heap = g_sci->getResMan()->findResource(ResourceId(kResourceTypeHeap, scr->_nr), 0);
 		assert(heap != 0);
 
-		scr->_heapStart = scr->_buf + scr->_scriptSize;
+		scr->_heapStart = scr->_buf + scr->getScriptSize();
 
-		assert(scr->_bufSize - scr->_scriptSize <= heap->size);
+		assert(scr->getBufSize() - scr->getScriptSize() <= heap->size);
 		memcpy(scr->_heapStart, heap->data, heap->size);
 	}
 }

Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/script.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -175,7 +175,7 @@
 	Script *scr = getScript(location.segment);
 	unsigned int count;
 
-	VERIFY(location.offset + 1 < (uint16)scr->_bufSize, "Locals beyond end of script\n");
+	VERIFY(location.offset + 1 < (uint16)scr->getBufSize(), "Locals beyond end of script\n");
 
 	if (getSciVersion() >= SCI_VERSION_1_1)
 		count = READ_SCI11ENDIAN_UINT16(scr->_buf + location.offset - 2);
@@ -185,9 +185,9 @@
 
 	scr->_localsOffset = location.offset;
 
-	if (!(location.offset + count * 2 + 1 < scr->_bufSize)) {
-		warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", location.offset, count, (uint)scr->_bufSize);
-		count = (scr->_bufSize - location.offset) >> 1;
+	if (!(location.offset + count * 2 + 1 < scr->getBufSize())) {
+		warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", location.offset, count, (uint)scr->getBufSize());
+		count = (scr->getBufSize() - location.offset) >> 1;
 	}
 
 	LocalVariables *locals = allocLocalsSegment(scr, count);

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -85,7 +85,7 @@
 		script_entity = (Script *)mobj;
 
 	scr = script_entity->_buf;
-	scr_size = script_entity->_bufSize;
+	scr_size = script_entity->getBufSize();
 
 	if (pos.offset >= scr_size) {
 		warning("Trying to disassemble beyond end of script");
@@ -303,7 +303,7 @@
 		if (mobj) {
 			Script *scr = (Script *)mobj;
 			byte *code_buf = scr->_buf;
-			int code_buf_size = scr->_bufSize;
+			int code_buf_size = scr->getBufSize();
 			int opcode = scriptState.xs->addr.pc.offset >= code_buf_size ? 0 : code_buf[scriptState.xs->addr.pc.offset];
 			int op = opcode >> 1;
 			int paramb1 = scriptState.xs->addr.pc.offset + 1 >= code_buf_size ? 0 : code_buf[scriptState.xs->addr.pc.offset + 1];

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -223,7 +223,7 @@
 				warning("getObject(): Trying to get an invalid object");
 		} else if (mobj->getType() == SEG_TYPE_SCRIPT) {
 			Script *scr = (Script *)mobj;
-			if (pos.offset <= scr->_bufSize && pos.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
+			if (pos.offset <= scr->getBufSize() && pos.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET
 			        && RAW_IS_OBJECT(scr->_buf + pos.offset)) {
 				obj = scr->getObject(pos.offset);
 			}

Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/segment.h	2010-05-30 16:14:31 UTC (rev 49327)
@@ -323,10 +323,6 @@
 public:
 	int _nr; /**< Script number */
 	byte *_buf; /**< Static data buffer, or NULL if not used */
-	size_t _bufSize;
-	size_t _scriptSize;
-	size_t _heapSize;
-
 	byte *_heapStart; /**< Start of heap if SCI1.1, NULL otherwise */
 
 	const uint16 *_exportTable; /**< Abs. offset of the export table or 0 if not present */
@@ -335,9 +331,18 @@
 	const byte *_synonyms; /**< Synonyms block or 0 if not present*/
 	int _numSynonyms; /**< Number of entries in the synonyms block */
 
+	uint32 getScriptSize() { return _scriptSize; }
+	uint32 getHeapSize() { return _heapSize; }
+	uint32 getBufSize() { return _bufSize; }
+
 protected:
 	int _lockers; /**< Number of classes and objects that require this script */
 
+private:
+	size_t _scriptSize;
+	size_t _heapSize;
+	size_t _bufSize;
+
 public:
 	/**
 	 * Table for objects, contains property variables.

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-05-30 15:17:29 UTC (rev 49326)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-05-30 16:14:31 UTC (rev 49327)
@@ -784,7 +784,7 @@
 				obj = s->_segMan->getObject(scriptState.xs->objp);
 				code_buf = scr->_buf;
 #ifndef DISABLE_VALIDATIONS
-				code_buf_size = scr->_bufSize;
+				code_buf_size = scr->getBufSize();
 #endif
 				local_script = s->_segMan->getScriptIfLoaded(scriptState.xs->local_segment);
 				if (!local_script) {
@@ -1398,7 +1398,7 @@
 
 			switch (g_sci->_features->detectLofsType()) {
 			case SCI_VERSION_1_1:
-				s->r_acc.offset = opparams[0] + local_script->_scriptSize;
+				s->r_acc.offset = opparams[0] + local_script->getScriptSize();
 				break;
 			case SCI_VERSION_1_MIDDLE:
 				s->r_acc.offset = opparams[0];
@@ -1420,7 +1420,7 @@
 
 			switch (g_sci->_features->detectLofsType()) {
 			case SCI_VERSION_1_1:
-				r_temp.offset = opparams[0] + local_script->_scriptSize;
+				r_temp.offset = opparams[0] + local_script->getScriptSize();
 				break;
 			case SCI_VERSION_1_MIDDLE:
 				r_temp.offset = opparams[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