From 44a8af5732ee316dfccf2f6c10d0b17bb3f4a633 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Mon, 7 Jan 2013 12:53:16 +0100 Subject: Fixing a bug (and another glitch) in Pointer. --- lout/object.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lout/object.cc b/lout/object.cc index 08ea0452..a081f023 100644 --- a/lout/object.cc +++ b/lout/object.cc @@ -124,16 +124,22 @@ int Pointer::hashValue() * return ((int*)value)[0] ^ ((int*)value)[1]; */ #if SIZEOF_VOID_P == 4 + // Assuming that sizeof(void*) == sizeof(int); on 32 bit systems. return (int)value; #else - return ((int*)value)[0] ^ ((int*)value)[1]; + // Assuming that sizeof(void*) == 2 * sizeof(int); on 64 bit + // systems (int is still 32 bit). + // Combine both parts of the pointer value *itself*, not what it + // points to, by first referencing it (operator "&"), then + // dereferencing it again (operator "[]"). + return ((int*)&value)[0] ^ ((int*)&value)[1]; #endif } void Pointer::intoStringBuffer(misc::StringBuffer *sb) { char buf[64]; - snprintf(buf, sizeof(buf), "0x%p", value); + snprintf(buf, sizeof(buf), "%p", value); sb->append(buf); } -- cgit v1.2.3