bigint.c (mrb_bint_powm): check zero division first.
MODIFY
mrbgems/mruby-bigint/core/bigint.c
mrbgems/mruby-bigint/core/bigint.c
@@ -1380,8 +1380,10 @@ mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_int exp, mrb_value mod)
switch (mrb_type(mod)) {
case MRB_TT_INTEGER:
{
+ mrb_int m = mrb_integer(mod);
+ if (m == 0) mrb_int_zerodiv(mrb);
struct RBigint *b2 = bint_new(mrb);
- struct RBigint *b3 = bint_new_int(mrb, mrb_integer(mod));
+ struct RBigint *b3 = bint_new_int(mrb, m);
mpz_powm(mrb, &b2->mp, &b->mp, exp, &b3->mp);
return mrb_obj_value(b3);
}
@@ -1389,6 +1391,7 @@ mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_int exp, mrb_value mod)
{
struct RBigint *b2 = bint_new(mrb);
struct RBigint *b3 = RBIGINT(mod);
+ if (uzero(&b3->mp)) mrb_int_zerodiv(mrb);
mpz_powm(mrb, &b2->mp, &b->mp, exp, &b3->mp);
return bint_norm(mrb, b3);
}

bigint.c (mrb_bint_powm): check zero division first.