From 95e43efc994af7d7ff85ef1722eac163be9cc5fd Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 19 May 2018 13:13:02 -0500 Subject: [PATCH] py/objfloat: Fix undefined integer behavior hashing negative zero. Under ubsan, when evaluating hash(-0.) the following diagnostic occurs: ../../py/objfloat.c:102:15: runtime error: negation of -9223372036854775808 cannot be represented in type 'mp_int_t' (aka 'long'); cast to an unsigned type to negate this value to itself So do just that, to tell the compiler that we want to perform this operation using modulo arithmetic rules. --- py/objfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/objfloat.c b/py/objfloat.c index 31c624778f..b62fe8e71d 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -99,7 +99,7 @@ typedef uint32_t mp_float_uint_t; } if (u.p.sgn) { - val = -val; + val = -(mp_uint_t)val; } return val;