diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-10-20 00:43:39 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-10-20 00:43:39 +0900 |
| commit | 9cb58a2252d25f81346ae3d4eefb1775d9ed548b (patch) | |
| tree | 3edd330761b2faa477b5f20bfb400db1d0576e8f | |
| parent | 9b2f4c4423ed11f12d6393ae1f0dd4fe3e51ffa0 (diff) | |
| download | mruby-9cb58a2252d25f81346ae3d4eefb1775d9ed548b.tar.gz mruby-9cb58a2252d25f81346ae3d4eefb1775d9ed548b.zip | |
Fixnum#succ may overflow
| -rw-r--r-- | src/numeric.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c index c309abf89..1cb47a8f2 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -710,7 +710,11 @@ int_to_i(mrb_state *mrb, mrb_value num) static mrb_value fix_succ(mrb_state *mrb, mrb_value num) { - return mrb_fixnum_value(mrb_fixnum(num)+1); + mrb_int x = mrb_fixnum(num); + + if (x == MRB_INT_MAX) /* fixnum overflow */ + return mrb_float_value(mrb, (double)x + 1.0); + return mrb_fixnum_value(x+1); } /* 15.2.8.3.19 */ |
