mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+4
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user