numeric.c: avoid integer overflow; close #5384

Since `mruby` does not have `Bignum`, `Float#divmod` could overflow, so
it will return `Float` values when the divided value does not fit in
`mrb_int`. This behavior will be changed when `Bignum` is introduced to
`mruby` in the future.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-03-19 07:15:05 +09:00
parent 087e1719e4
commit eb07030308
+4 -1
View File
@@ -1016,7 +1016,10 @@ flo_divmod(mrb_state *mrb, mrb_value x)
mrb_value a, b;
flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
a = mrb_int_value(mrb, (mrb_int)div);
if (!FIXABLE_FLOAT(div))
a = mrb_float_value(mrb, div);
else
a = mrb_int_value(mrb, (mrb_int)div);
b = mrb_float_value(mrb, mod);
return mrb_assoc_new(mrb, a, b);
}