Commit 07308a2f authored by dearblue's avatar dearblue

Suppress compiler warnings for mruby-time; fix #4600

Warnings:

- If `MRB_TIME_T_UINT` is defined, the compiler issues a warning with an
  integer comparison of different signs.
- It is mentioned that the `usec` variable passed to the
  `mrb_to_time_t()` function may not be initialized
parent c883f4e3
...@@ -213,6 +213,16 @@ typedef mrb_int mrb_sec; ...@@ -213,6 +213,16 @@ typedef mrb_int mrb_sec;
#define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec) #define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec)
#endif #endif
#ifdef MRB_TIME_T_UINT
typedef uint64_t mrb_time_int;
# define MRB_TIME_MIN 0
# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? UINT32_MAX : UINT64_MAX)
#else
typedef int64_t mrb_time_int;
# define MRB_TIME_MIN (sizeof(time_t) <= 4 ? INT32_MIN : INT64_MIN)
# define MRB_TIME_MAX (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX)
#endif
static time_t static time_t
mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
{ {
...@@ -225,21 +235,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) ...@@ -225,21 +235,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
mrb_float f = mrb_float(obj); mrb_float f = mrb_float(obj);
mrb_check_num_exact(mrb, f); mrb_check_num_exact(mrb, f);
# ifndef MRB_TIME_T_UINT if (f > (mrb_float)MRB_TIME_MAX || (mrb_float)MRB_TIME_MIN > f) {
if (sizeof(time_t) == 4 && (f > (mrb_float)INT32_MAX || (mrb_float)INT32_MIN > f)) {
goto out_of_range;
}
if (sizeof(time_t) == 8 && (f > (mrb_float)INT64_MAX || (mrb_float)INT64_MIN > f)) {
goto out_of_range;
}
# else
if (sizeof(time_t) == 4 && (f > (mrb_float)UINT32_MAX || (mrb_float)0 > f)) {
goto out_of_range;
}
if (sizeof(time_t) == 8 && (f > (mrb_float)UINT64_MAX || (mrb_float)0 > f)) {
goto out_of_range; goto out_of_range;
} }
# endif
if (usec) { if (usec) {
t = (time_t)f; t = (time_t)f;
...@@ -256,21 +254,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) ...@@ -256,21 +254,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
{ {
mrb_int i = mrb_int(mrb, obj); mrb_int i = mrb_int(mrb, obj);
#ifndef MRB_TIME_T_UINT if ((mrb_time_int)i > MRB_TIME_MAX || MRB_TIME_MIN > i) {
if (sizeof(time_t) == 4 && (i > INT32_MAX || INT32_MIN > i)) {
goto out_of_range;
}
if (sizeof(time_t) == 8 && (i > INT64_MAX || INT64_MIN > i)) {
goto out_of_range;
}
#else
if (sizeof(time_t) == 4 && (i > UINT32_MAX || 0 > i)) {
goto out_of_range;
}
if (sizeof(time_t) == 8 && (i > UINT64_MAX || 0 > i)) {
goto out_of_range; goto out_of_range;
} }
#endif
t = (time_t)i; t = (time_t)i;
if (usec) { *usec = 0; } if (usec) { *usec = 0; }
...@@ -283,7 +269,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) ...@@ -283,7 +269,9 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec)
out_of_range: out_of_range:
mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", obj); mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", obj);
return 0; /* suppress compiler warnings */ /* not reached */
if (usec) { *usec = 0; }
return 0;
} }
/** 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
......
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