Skip to content

Commit 15f37f7

Browse files
committed
#34997: check first to avoid executing the UB
1 parent 910a2e9 commit 15f37f7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sage/arith/long.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ cdef inline bint integer_check_long_py(x, long* value, int* err):
320320

321321
cdef long lead
322322
cdef long lead_2_overflow = (<long>1) << (BITS_IN_LONG - PyLong_SHIFT)
323-
cdef long lead_3_overflow = (<long>1) << (BITS_IN_LONG - 2 * PyLong_SHIFT)
323+
cdef long lead_3_overflow
324324
if BITS_IN_LONG < 2 * PyLong_SHIFT:
325325
# in this case 3 digit is always overflow
326326
lead_3_overflow = 0
327+
else:
328+
lead_3_overflow = (<long>1) << (BITS_IN_LONG - 2 * PyLong_SHIFT)
327329
if size == 0:
328330
value[0] = 0
329331
err[0] = 0

0 commit comments

Comments
 (0)