[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
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.225,2.226 script_v90he.cpp,2.9,2.10
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.226,2.227 script_v72he.cpp,2.56,2.57 script_v80he.cpp,2.4,2.5 script_v90he.cpp,2.10,2.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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);
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.225,2.226 script_v90he.cpp,2.9,2.10
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.226,2.227 script_v72he.cpp,2.56,2.57 script_v80he.cpp,2.4,2.5 script_v90he.cpp,2.10,2.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list