From ea1911d23f492ef3874029a28ac1c28cd1fdb838 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 3 Dec 2019 22:50:50 +0900 Subject: Silence Clang warning with `MRB_INT64` and `MRB_32BIT` in `time.c` Silence the following warnings: ``` /mruby/mrbgems/mruby-time/src/time.c:871:15: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare] if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) { ~~~~~~~ ^ ~~~~~~~~~~~ /mruby/mrbgems/mruby-time/src/time.c:871:40: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare] if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) { ~~~~~~~ ^ ~~~~~~~~~~~ /mruby/mrbgems/mruby-time/src/time.c:887:16: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare] if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) { ~~~~~~~~ ^ ~~~~~~~~~~~ /mruby/mrbgems/mruby-time/src/time.c:887:42: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare] if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) { ~~~~~~~~ ^ ~~~~~~~~~~~ ``` --- mrbgems/mruby-time/src/time.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 7024cc36a..46e32839a 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #ifndef MRB_DISABLE_STDIO @@ -223,6 +224,13 @@ typedef int64_t mrb_time_int; # define MRB_TIME_MAX (sizeof(time_t) <= 4 ? INT32_MAX : INT64_MAX) #endif +static mrb_bool +fixable_time_t_p(time_t v) +{ + if (MRB_INT_MIN <= MRB_TIME_MIN && MRB_TIME_MAX <= MRB_INT_MAX) return TRUE; + return FIXABLE(v); +} + static time_t mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) { @@ -868,7 +876,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self) tm = time_get_ptr(mrb, self); #ifndef MRB_WITHOUT_FLOAT - if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) { + if (!fixable_time_t_p(tm->sec)) { return mrb_float_value(mrb, (mrb_float)tm->sec); } #endif @@ -884,7 +892,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self) tm = time_get_ptr(mrb, self); #ifndef MRB_WITHOUT_FLOAT - if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) { + if (!fixable_time_t_p(tm->usec)) { return mrb_float_value(mrb, (mrb_float)tm->usec); } #endif -- cgit v1.2.3