summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-time/src/time.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-08-03 20:36:20 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-08-03 20:36:20 +0900
commit0878900fda882cdf597ba2bef9e2c8fe1809647a (patch)
treef0a34a2ad74f83372cf9290d1ccb936760b785d3 /mrbgems/mruby-time/src/time.c
parent5e5fad2f25754b7fef0dd6936918b3df0ccd6ef0 (diff)
downloadmruby-0878900fda882cdf597ba2bef9e2c8fe1809647a.tar.gz
mruby-0878900fda882cdf597ba2bef9e2c8fe1809647a.zip
Time#to_i and Time#usec should care about mrb_int overflow on MRB_INT16; ref #2495
Diffstat (limited to 'mrbgems/mruby-time/src/time.c')
-rw-r--r--mrbgems/mruby-time/src/time.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 8903c522a..f9dd0cb33 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -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);
}