numeric.c (int_pow): should not overflow.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-04-21 11:35:52 +09:00
parent e7d0e6fd5a
commit 9dd45df804
+4
View File
@@ -85,7 +85,11 @@ mrb_int_pow(mrb_state *mrb, mrb_value x)
for (;;) {
if (exp & 1) {
if (mrb_int_mul_overflow(result, base, &result)) {
#ifdef MRB_USE_BIGINT
return mrb_bint_pow(mrb, mrb_bint_new_int(mrb, mrb_integer(x)), y);
#else
mrb_int_overflow(mrb, "power");
#endif
}
}
exp >>= 1;