Discussion:
dereferencing type-punned pointer warning
Johannes Hofmann
2013-01-14 20:57:46 UTC
Permalink
Hi,

line 135 in lout object.cc:
return ((int*)&value)[0] ^ ((int*)&value)[1];

causes the following error on 64bit systems for me:

warning: dereferencing type-punned pointer will
break strict-aliasing rules

Can we replace it like this:

diff -r dd6f2d1eb15a lout/object.cc
--- a/lout/object.cc Mon Jan 14 10:26:37 2013 -0300
+++ b/lout/object.cc Mon Jan 14 21:56:46 2013 +0100
@@ -21,6 +21,7 @@

#include "object.hh"
#include <stdio.h>
+#include <stdint.h>
#include <config.h>

namespace lout {
@@ -132,7 +133,7 @@
// 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];
+ return ((intptr_t)value >> 32) ^ ((intptr_t)value);
#endif
}

Cheers,
Johannes
Sebastian Geerken
2013-01-22 19:34:44 UTC
Permalink
Post by Johannes Hofmann
return ((int*)&value)[0] ^ ((int*)&value)[1];
warning: dereferencing type-punned pointer will
break strict-aliasing rules
Can we replace it like this: [...]
Committed, and tested with an amd64 system.

Actually, this code is never used in dillo, but in objman-test, for
which I fixed a bug in this method.

Sebastian

Loading...