From 26e0f72a6bb214f1f53326c7b2325715afe43fb6 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 22 Apr 2011 09:19:36 +0300 Subject: Add 32/64 bit consistency in hashing. --- array.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'array.c') diff --git a/array.c b/array.c index 15053bb0..3d7ff2fa 100644 --- a/array.c +++ b/array.c @@ -427,9 +427,15 @@ awk_hash(const char *s, size_t len, unsigned long hsize, size_t *code) * Even more speed: * #define HASHC h = *s++ + 65599 * h * Because 65599 = pow(2, 6) + pow(2, 16) - 1 we multiply by shifts + * + * 4/2011: Force the results to 32 bits, to get the same + * result on both 32- and 64-bit systems. This may be a + * bad idea. */ #define HASHC htmp = (h << 6); \ - h = *s++ + htmp + (htmp << 10) - h + h = *s++ + htmp + (htmp << 10) - h ; \ + htmp &= 0xFFFFFFFF; \ + h &= 0xFFFFFFFF; unsigned long htmp; -- cgit v1.2.3