diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-17 22:40:02 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-17 22:41:43 +0900 |
| commit | 5abb283dd7323e63b12ea14cc98b35f77ba771e7 (patch) | |
| tree | 358e167cba1f0db94c978acc213590d89e5a8137 /mrbgems | |
| parent | 1f12525154e6a6d81d0848f74bef82a29e01ea3c (diff) | |
| download | mruby-5abb283dd7323e63b12ea14cc98b35f77ba771e7.tar.gz mruby-5abb283dd7323e63b12ea14cc98b35f77ba771e7.zip | |
Check division overflow (`MRB_INT_MIN` and `-1`).
Diffstat (limited to 'mrbgems')
| -rw-r--r-- | mrbgems/mruby-rational/src/rational.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index a35f2f023..85b1dff07 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -236,6 +236,9 @@ rational_m_int(mrb_state *mrb, mrb_int n, mrb_int d) b = a % b; a = tmp; } + if ((n == MRB_INT_MIN || d == MRB_INT_MIN) && a == -1) { + mrb_raise(mrb, E_RANGE_ERROR, "integer overflow in rational"); + } return rational_new(mrb, n/a, d/a); } |
