aboutsummaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2018-05-19 11:25:03 -0500
committerDamien George <damien.p.george@gmail.com>2018-05-21 12:42:22 +1000
commit60eb5305f637e21f7ec4006924c06518ca6de476 (patch)
treee3ae16cfcbef19fc5c28d87dcc15b75bdd722852 /py/objfloat.c
parent4f71a2a75a71b89dad2eed147d6e237b633b878e (diff)
py/objfloat: Fix undefined shifting behavior in high-quality float hash.
When computing e.g. hash(0.4e3) with ubsan enabled, a diagnostic like the following would occur: ../../py/objfloat.c:91:30: runtime error: shift exponent 44 is too large for 32-bit type 'int' By casting constant "1" to the right type the intended value is preserved.
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index e4d5a6570..31c624778 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -88,7 +88,7 @@ typedef uint32_t mp_float_uint_t;
if (adj_exp <= MP_FLOAT_FRAC_BITS) {
// number may have a fraction; xor the integer part with the fractional part
val = (frc >> (MP_FLOAT_FRAC_BITS - adj_exp))
- ^ (frc & ((1 << (MP_FLOAT_FRAC_BITS - adj_exp)) - 1));
+ ^ (frc & (((mp_float_uint_t)1 << (MP_FLOAT_FRAC_BITS - adj_exp)) - 1));
} else if ((unsigned int)adj_exp < BITS_PER_BYTE * sizeof(mp_int_t) - 1) {
// the number is a (big) whole integer and will fit in val's signed-width
val = (mp_int_t)frc << (adj_exp - MP_FLOAT_FRAC_BITS);