numeric.c (int_div): add checks for division by zero.
MODIFY
mrbgems/mruby-bigint/core/bigint.c
mrbgems/mruby-bigint/core/bigint.c
@@ -1180,6 +1180,9 @@ mrb_bint_div(mrb_state *mrb, mrb_value x, mrb_value y)
return mrb_float_value(mrb,v1*v2);
}
#endif
+ if (mrb_integer_p(y) && mrb_integer(y) == 0) {
+ mrb_int_zerodiv(mrb);
+ }
y = mrb_as_bint(mrb, y);
struct RBigint *b = RBIGINT(x);
struct RBigint *b2 = RBIGINT(y);

MODIFY
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
#include <mruby.h>
#include <mruby/class.h>
#include <mruby/numeric.h>
+#include <mruby/internal.h>
#include <mruby/presym.h>
#ifdef MRB_NO_FLOAT
@@ -308,6 +309,9 @@ mrb_complex_div(mrb_state *mrb, mrb_value self, mrb_value rhs)
a = complex_ptr(mrb, self);
if (mrb_type(rhs) != MRB_TT_COMPLEX) {
+ if (mrb_integer_p(rhs) && mrb_integer(rhs) == 0) {
+ mrb_int_zerodiv(mrb);
+ }
mrb_float f = mrb_as_float(mrb, rhs);
return complex_new(mrb, mrb_div_float(a->real, f), mrb_div_float(a->imaginary, f));
}

MODIFY
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
#include <mruby.h>
#include <mruby/class.h>
#include <mruby/numeric.h>
+#include <mruby/internal.h>
#include <mruby/presym.h>
#ifndef MRB_NO_FLOAT
@@ -647,6 +648,7 @@ mrb_rational_div(mrb_state *mrb, mrb_value x, mrb_value y)
case MRB_TT_INTEGER:
{
mrb_int z = mrb_integer(y);
+ if (z == 0) mrb_int_zerodiv(mrb);
if (mrb_int_mul_overflow(p1->denominator, z, &z)) rat_overflow(mrb);
return rational_new_i(mrb, p1->numerator, z);
}

MODIFY
src/numeric.c
src/numeric.c
@@ -160,7 +160,6 @@ int_div(mrb_state *mrb, mrb_value x)
#endif
mrb_int a = mrb_integer(x);
- if (a == 0) return mrb_fixnum_value(0);
if (mrb_integer_p(y)) {
return mrb_div_int_value(mrb, a, mrb_integer(y));
}

numeric.c (int_div): add checks for division by zero.