Raise an exception in time_update_datetime().

The function used to return NULL on error, but not checked in the
caller site.
parent 6ec14a21
...@@ -183,7 +183,7 @@ static const struct mrb_data_type mrb_time_type = { "Time", mrb_free }; ...@@ -183,7 +183,7 @@ static const struct mrb_data_type mrb_time_type = { "Time", mrb_free };
/** Updates the datetime of a mrb_time based on it's timezone and /** Updates the datetime of a mrb_time based on it's timezone and
seconds setting. Returns self on success, NULL of failure. */ seconds setting. Returns self on success, NULL of failure. */
static struct mrb_time* static struct mrb_time*
mrb_time_update_datetime(struct mrb_time *self) time_update_datetime(mrb_state *mrb, struct mrb_time *self)
{ {
struct tm *aid; struct tm *aid;
...@@ -193,7 +193,11 @@ mrb_time_update_datetime(struct mrb_time *self) ...@@ -193,7 +193,11 @@ mrb_time_update_datetime(struct mrb_time *self)
else { else {
aid = localtime_r(&self->sec, &self->datetime); aid = localtime_r(&self->sec, &self->datetime);
} }
if (!aid) return NULL; if (!aid) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, self->sec));
/* not reached */
return NULL;
}
#ifdef NO_GMTIME_R #ifdef NO_GMTIME_R
self->datetime = *aid; /* copy data */ self->datetime = *aid; /* copy data */
#endif #endif
...@@ -238,7 +242,7 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone) ...@@ -238,7 +242,7 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
tm->usec -= 1000000; tm->usec -= 1000000;
} }
tm->timezone = timezone; tm->timezone = timezone;
mrb_time_update_datetime(tm); time_update_datetime(mrb, tm);
return tm; return tm;
} }
...@@ -290,7 +294,7 @@ current_mrb_time(mrb_state *mrb) ...@@ -290,7 +294,7 @@ current_mrb_time(mrb_state *mrb)
} }
#endif #endif
tm->timezone = MRB_TIMEZONE_LOCAL; tm->timezone = MRB_TIMEZONE_LOCAL;
mrb_time_update_datetime(tm); time_update_datetime(mrb, tm);
return tm; return tm;
} }
...@@ -556,7 +560,7 @@ mrb_time_getutc(mrb_state *mrb, mrb_value self) ...@@ -556,7 +560,7 @@ mrb_time_getutc(mrb_state *mrb, mrb_value self)
tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm)); tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
*tm2 = *tm; *tm2 = *tm;
tm2->timezone = MRB_TIMEZONE_UTC; tm2->timezone = MRB_TIMEZONE_UTC;
mrb_time_update_datetime(tm2); time_update_datetime(mrb, tm2);
return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2); return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2);
} }
...@@ -571,7 +575,7 @@ mrb_time_getlocal(mrb_state *mrb, mrb_value self) ...@@ -571,7 +575,7 @@ mrb_time_getlocal(mrb_state *mrb, mrb_value self)
tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm)); tm2 = (struct mrb_time *)mrb_malloc(mrb, sizeof(*tm));
*tm2 = *tm; *tm2 = *tm;
tm2->timezone = MRB_TIMEZONE_LOCAL; tm2->timezone = MRB_TIMEZONE_LOCAL;
mrb_time_update_datetime(tm2); time_update_datetime(mrb, tm2);
return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2); return mrb_time_wrap(mrb, mrb_obj_class(mrb, self), tm2);
} }
...@@ -649,7 +653,7 @@ mrb_time_localtime(mrb_state *mrb, mrb_value self) ...@@ -649,7 +653,7 @@ mrb_time_localtime(mrb_state *mrb, mrb_value self)
tm = time_get_ptr(mrb, self); tm = time_get_ptr(mrb, self);
tm->timezone = MRB_TIMEZONE_LOCAL; tm->timezone = MRB_TIMEZONE_LOCAL;
mrb_time_update_datetime(tm); time_update_datetime(mrb, tm);
return self; return self;
} }
...@@ -746,7 +750,7 @@ mrb_time_utc(mrb_state *mrb, mrb_value self) ...@@ -746,7 +750,7 @@ mrb_time_utc(mrb_state *mrb, mrb_value self)
tm = time_get_ptr(mrb, self); tm = time_get_ptr(mrb, self);
tm->timezone = MRB_TIMEZONE_UTC; tm->timezone = MRB_TIMEZONE_UTC;
mrb_time_update_datetime(tm); time_update_datetime(mrb, tm);
return self; return self;
} }
......
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