Check division overflow (`MRB_INT_MIN` and `-1`).

parent 1f125251
...@@ -236,6 +236,9 @@ rational_m_int(mrb_state *mrb, mrb_int n, mrb_int d) ...@@ -236,6 +236,9 @@ rational_m_int(mrb_state *mrb, mrb_int n, mrb_int d)
b = a % b; b = a % b;
a = tmp; 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); return rational_new(mrb, n/a, d/a);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment