From eb392cb6434940615164f24da0e3352aca94aa80 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 30 Jul 2022 09:06:49 +0900 Subject: [PATCH] numeric.c (mrb_float_to_integer): check for RangeError. Otherwise flo_to_i raises FloatDomainError instead. --- src/numeric.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/numeric.c b/src/numeric.c index daf803fb0..e90b70c5f 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1585,6 +1585,10 @@ mrb_float_to_integer(mrb_state *mrb, mrb_value x) if (!mrb_float_p(x)) { mrb_raise(mrb, E_TYPE_ERROR, "non float value"); } + float f = mrb_float(x); + if (isinf(f) || isnan(f)) { + mrb_raisef(mrb, E_RANGE_ERROR, "float %f out of range", f); + } return flo_to_i(mrb, x); } #endif