Skip to content

Commit 7cc024a

Browse files
authored
[mypyc] Fix C errors about shifting negative integers (#13876)
Fixes #13819.
1 parent 319d745 commit 7cc024a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: mypyc/lib-rt/int_ops.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ int64_t CPyInt64_Divide(int64_t x, int64_t y) {
544544
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
545545
return CPY_LL_INT_ERROR;
546546
}
547-
if (y == -1 && x == -1LL << 63) {
547+
if (y == -1 && x == INT64_MIN) {
548548
PyErr_SetString(PyExc_OverflowError, "integer division overflow");
549549
return CPY_LL_INT_ERROR;
550550
}
@@ -562,7 +562,7 @@ int64_t CPyInt64_Remainder(int64_t x, int64_t y) {
562562
return CPY_LL_INT_ERROR;
563563
}
564564
// Edge case: avoid core dump
565-
if (y == -1 && x == -1LL << 63) {
565+
if (y == -1 && x == INT64_MIN) {
566566
return 0;
567567
}
568568
int64_t d = x % y;
@@ -607,7 +607,7 @@ int32_t CPyInt32_Divide(int32_t x, int32_t y) {
607607
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
608608
return CPY_LL_INT_ERROR;
609609
}
610-
if (y == -1 && x == -1LL << 31) {
610+
if (y == -1 && x == INT32_MIN) {
611611
PyErr_SetString(PyExc_OverflowError, "integer division overflow");
612612
return CPY_LL_INT_ERROR;
613613
}
@@ -625,7 +625,7 @@ int32_t CPyInt32_Remainder(int32_t x, int32_t y) {
625625
return CPY_LL_INT_ERROR;
626626
}
627627
// Edge case: avoid core dump
628-
if (y == -1 && x == -1LL << 31) {
628+
if (y == -1 && x == INT32_MIN) {
629629
return 0;
630630
}
631631
int32_t d = x % y;

0 commit comments

Comments
 (0)