From 15f37f76cc0978923908b3d51c469549d5b22e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Tue, 7 Feb 2023 23:12:53 -0300 Subject: [PATCH] #34997: check first to avoid executing the UB --- src/sage/arith/long.pxd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/arith/long.pxd b/src/sage/arith/long.pxd index 16d13512f68..d96b98f247c 100644 --- a/src/sage/arith/long.pxd +++ b/src/sage/arith/long.pxd @@ -320,10 +320,12 @@ cdef inline bint integer_check_long_py(x, long* value, int* err): cdef long lead cdef long lead_2_overflow = (1) << (BITS_IN_LONG - PyLong_SHIFT) - cdef long lead_3_overflow = (1) << (BITS_IN_LONG - 2 * PyLong_SHIFT) + cdef long lead_3_overflow if BITS_IN_LONG < 2 * PyLong_SHIFT: # in this case 3 digit is always overflow lead_3_overflow = 0 + else: + lead_3_overflow = (1) << (BITS_IN_LONG - 2 * PyLong_SHIFT) if size == 0: value[0] = 0 err[0] = 0