mrubyを超漢字で動作させる
修訂 | e749267909f879ac3e8b8cf681c2c6067d056a96 (tree) |
---|---|
時間 | 2014-07-02 10:28:10 |
作者 | Yukihiro "Matz" Matsumoto <matz@ruby...> |
Commiter | Yukihiro "Matz" Matsumoto |
time overflow check; ref #2337
@@ -201,6 +201,13 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone) | ||
201 | 201 | |
202 | 202 | tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time)); |
203 | 203 | tm->sec = (time_t)sec; |
204 | + if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) { | |
205 | + goto out_of_range; | |
206 | + } | |
207 | + else if ((sec > 0 && tm->sec < 0) || (sec < 0 && (double)tm->sec > sec)) { | |
208 | + out_of_range: | |
209 | + mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec)); | |
210 | + } | |
204 | 211 | tm->usec = (time_t)((sec - tm->sec) * 1.0e6 + usec); |
205 | 212 | while (tm->usec < 0) { |
206 | 213 | tm->sec--; |