diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-19 07:15:05 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-19 07:15:05 +0900 |
| commit | eb070303080b24458d3740424aa7aa8a45fa49eb (patch) | |
| tree | fd66290265a16382cad6f6a6e6e98e29147ae2e4 /src/numeric.c | |
| parent | 087e1719e45ae51b728aa8b15edd30d9ef757a98 (diff) | |
| download | mruby-eb070303080b24458d3740424aa7aa8a45fa49eb.tar.gz mruby-eb070303080b24458d3740424aa7aa8a45fa49eb.zip | |
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.
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c index 74e3a8b82..b931a0f35 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -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); } |
