Skip to content

Commit

Permalink
[mypyc] Fix C errors about shifting negative integers (#13876)
Browse files Browse the repository at this point in the history
Fixes #13819.
  • Loading branch information
JukkaL authored Oct 12, 2022
1 parent 319d745 commit 7cc024a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mypyc/lib-rt/int_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ int64_t CPyInt64_Divide(int64_t x, int64_t y) {
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
return CPY_LL_INT_ERROR;
}
if (y == -1 && x == -1LL << 63) {
if (y == -1 && x == INT64_MIN) {
PyErr_SetString(PyExc_OverflowError, "integer division overflow");
return CPY_LL_INT_ERROR;
}
Expand All @@ -562,7 +562,7 @@ int64_t CPyInt64_Remainder(int64_t x, int64_t y) {
return CPY_LL_INT_ERROR;
}
// Edge case: avoid core dump
if (y == -1 && x == -1LL << 63) {
if (y == -1 && x == INT64_MIN) {
return 0;
}
int64_t d = x % y;
Expand Down Expand Up @@ -607,7 +607,7 @@ int32_t CPyInt32_Divide(int32_t x, int32_t y) {
PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
return CPY_LL_INT_ERROR;
}
if (y == -1 && x == -1LL << 31) {
if (y == -1 && x == INT32_MIN) {
PyErr_SetString(PyExc_OverflowError, "integer division overflow");
return CPY_LL_INT_ERROR;
}
Expand All @@ -625,7 +625,7 @@ int32_t CPyInt32_Remainder(int32_t x, int32_t y) {
return CPY_LL_INT_ERROR;
}
// Edge case: avoid core dump
if (y == -1 && x == -1LL << 31) {
if (y == -1 && x == INT32_MIN) {
return 0;
}
int32_t d = x % y;
Expand Down

0 comments on commit 7cc024a

Please sign in to comment.