summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-07-31 00:58:12 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-07-31 00:58:12 +0900
commit96ac49b75b5981c7b286da8ef60236de5412d342 (patch)
treed449f3eec9613369603448ec8d82fd749ddd2d61 /src
parentc31e1ea798f9a67917258147ba2cd33cf1ca851a (diff)
downloadmruby-96ac49b75b5981c7b286da8ef60236de5412d342.tar.gz
mruby-96ac49b75b5981c7b286da8ef60236de5412d342.zip
Avoid `MRB_INT_MIN` to apply `fixdivmod`.
`MRB_INT_MIN` is the only integer value that has no corresponding positive integer value (i.e. `-MRB_INT_MIN` = `MRB_INT_MIN`).
Diffstat (limited to 'src')
-rw-r--r--src/numeric.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/numeric.c b/src/numeric.c
index 6cddcdada..b143b2f67 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -891,14 +891,14 @@ static mrb_value
fix_mod(mrb_state *mrb, mrb_value x)
{
mrb_value y;
- mrb_int a;
+ mrb_int a, b;
mrb_get_args(mrb, "o", &y);
a = mrb_fixnum(x);
- if (mrb_fixnum_p(y)) {
- mrb_int b, mod;
+ if (mrb_fixnum_p(y) && a != MRB_INT_MIN && (b=mrb_fixnum(y)) != MRB_INT_MIN) {
+ mrb_int mod;
- if ((b=mrb_fixnum(y)) == 0) {
+ if (b == 0) {
#ifdef MRB_WITHOUT_FLOAT
/* ZeroDivisionError */
return mrb_fixnum_value(0);