Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bigint.c (mrb_bint_powm): check zero division first.
  • Loading branch information
matz committed Aug 26, 2022
1 parent 818ca41 commit ef19740
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mrbgems/mruby-bigint/core/bigint.c
Expand Up @@ -1380,15 +1380,18 @@ 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);
}
case MRB_TT_BIGINT:
{
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);
}
Expand Down

0 comments on commit ef19740

Please sign in to comment.