From 91f227cad7cd6a1a36c8cac75e56d1308821fe34 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Wed, 20 Jan 2010 13:50:48 -0500 Subject: [PATCH] hash: Prevent warnings about strict aliasing rules. Some versions of GCC complain about violations of strict aliasing rules due to a cast between different pointer types. This avoids any aliasing by copying the value first. --- lib/hash.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/hash.h b/lib/hash.h index 3f140381c..5f6409cb1 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -83,8 +83,11 @@ static inline uint32_t hash_boolean(bool x, uint32_t basis) static inline uint32_t hash_double(double x, uint32_t basis) { - BUILD_ASSERT_DECL(sizeof x == 8); - return hash_2words((const uint32_t *) &x, basis); + uint32_t value[2]; + BUILD_ASSERT_DECL(sizeof x == sizeof value); + + memcpy(value, &x, sizeof value); + return hash_2words(value, basis); } static inline uint32_t hash_pointer(const void *p, uint32_t basis) -- 2.43.0