From e766cb3e578fcfb3f21dd8f4a95cd4296b704c89 Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Sat, 5 Oct 2024 05:54:32 +0900 Subject: [PATCH] Suppress warnings in `time_init_parse` function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building Ruby on Ubuntu 22.04 and GCC 11.4.0, the following warning appeared. And this change has suppressed warning. ``` compiling ../ruby/time.c ../ruby/time.c: In function ‘time_init_parse’: ../ruby/time.c:2650:21: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare] 2650 | if (ndigits < TIME_SCALE_NUMDIGITS) { | ^ ../ruby/time.c:2654:26: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare] 2654 | else if (ndigits > TIME_SCALE_NUMDIGITS) { | ``` --- time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/time.c b/time.c index e3f58e3645..54db29c2af 100644 --- a/time.c +++ b/time.c @@ -2647,11 +2647,11 @@ time_init_parse(rb_execution_context_t *ec, VALUE time, VALUE str, VALUE zone, V } if (!NIL_P(subsec)) { /* subseconds is the last using ndigits */ - if (ndigits < TIME_SCALE_NUMDIGITS) { + if (ndigits < (size_t)TIME_SCALE_NUMDIGITS) { VALUE mul = rb_int_positive_pow(10, TIME_SCALE_NUMDIGITS - ndigits); subsec = rb_int_mul(subsec, mul); } - else if (ndigits > TIME_SCALE_NUMDIGITS) { + else if (ndigits > (size_t)TIME_SCALE_NUMDIGITS) { VALUE num = rb_int_positive_pow(10, ndigits - TIME_SCALE_NUMDIGITS); subsec = rb_rational_new(subsec, num); }