From 0b9cda5018bbbd0302814197066f0039fd6b4452 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 18 Sep 2015 09:25:26 -0600 Subject: [PATCH] avoid undefined behavior in hashing inexacts Casting a negative floating-point number to an unsigned integer is not ok. Corece to a signed integer, first. Thanks to John Regehr for help. --- racket/src/racket/src/hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/racket/src/racket/src/hash.c b/racket/src/racket/src/hash.c index 2a846d72bb..7013f3da7c 100644 --- a/racket/src/racket/src/hash.c +++ b/racket/src/racket/src/hash.c @@ -1117,7 +1117,7 @@ XFORM_NONGCING static uintptr_t dbl_hash_val(double d) d = frexp(d, &e); } - return ((uintptr_t)(d * (1 << 30))) + e; + return ((uintptr_t)(intptr_t)(d * (1 << 30))) + (uintptr_t)e; } XFORM_NONGCING static uintptr_t dbl_hash2_val(double d)