Time#to_i and Time#usec should care about mrb_int overflow on MRB_INT16; ref #2495

parent 5e5fad2f
......@@ -673,6 +673,11 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self)
struct mrb_time *tm;
tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
#ifdef MRB_INT16
if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
return mrb_float_value(mrb, (mrb_float)tm->sec);
}
#endif
return mrb_fixnum_value((mrb_int)tm->sec);
}
......@@ -684,6 +689,11 @@ mrb_time_usec(mrb_state *mrb, mrb_value self)
struct mrb_time *tm;
tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time);
#ifdef MRB_INT16
if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
return mrb_float_value(mrb, (mrb_float)tm->usec);
}
#endif
return mrb_fixnum_value((mrb_int)tm->usec);
}
......
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