Skip to content

Commit 95e43ef

Browse files
jeplerdpgeorge
authored andcommitted
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.
1 parent c4dafce commit 95e43ef

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

py/objfloat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ typedef uint32_t mp_float_uint_t;
9999
}
100100

101101
if (u.p.sgn) {
102-
val = -val;
102+
val = -(mp_uint_t)val;
103103
}
104104

105105
return val;

0 commit comments

Comments
 (0)