mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Check division overflow (MRB_INT_MIN and -1).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user