[Scummvm-cvs-logs] CVS: scummvm/sword2 memory.cpp,1.28,1.29

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Mon Sep 6 23:33:52 CEST 2004


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13269

Modified Files:
	memory.cpp 
Log Message:
Much like an early civilization with no concept of the number zero, the
new memory manager didn't have the concept of the NULL pointer. Now it
does.

If ScummVM ever crashed for you when using the phone early in the game,
this patch hopefully fixes that bug. (If it didn't crash for you, memory
block zero was still allocated, so 0 still decoded to a valid pointer.) 


Index: memory.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/memory.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- memory.cpp	10 Jun 2004 06:33:11 -0000	1.28
+++ memory.cpp	7 Sep 2004 06:29:57 -0000	1.29
@@ -37,6 +37,8 @@
 // could only handle up to 999 blocks of memory. That means we can encode a
 // pointer as a 10-bit id and a 22-bit offset into the block. Judging by early
 // testing, both should be plenty.
+//
+// The number zero is used to represent the NULL pointer.
 
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
@@ -92,6 +94,9 @@
 }
 
 int32 MemoryManager::encodePtr(byte *ptr) {
+	if (ptr == NULL)
+		return 0;
+
 	int idx = findPointerInIndex(ptr);
 
 	assert(idx != -1);
@@ -99,15 +104,18 @@
 	uint32 id = _memBlockIndex[idx]->id;
 	uint32 offset = ptr - _memBlocks[id].ptr;
 
-	assert(id <= 0x03ff);
+	assert(id < 0x03ff);
 	assert(offset <= 0x003fffff);
 	assert(offset < _memBlocks[id].size);
 
-	return (id << 22) | (ptr - _memBlocks[id].ptr);
+	return ((id + 1) << 22) | (ptr - _memBlocks[id].ptr);
 }
 
 byte *MemoryManager::decodePtr(int32 n) {
-	uint32 id = (n & 0xffc00000) >> 22;
+	if (n == 0)
+		return NULL;
+
+	uint32 id = ((n & 0xffc00000) >> 22) - 1;
 	uint32 offset = n & 0x003fffff;
 
 	assert(_memBlocks[id].ptr);





More information about the Scummvm-git-logs mailing list