From 01095757986d9c93151cab01bb39d888c2094a78 Mon Sep 17 00:00:00 2001 From: Michal Sekletar Date: Thu, 13 May 2021 10:52:42 +0200 Subject: [PATCH] rfkill: don't compare values of different signedness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFKILL_EVENT_SIZE_V1 is defined as follows in . #define RFKILL_EVENT_SIZE_V1 sizeof(struct rfkill_event) Avoid warning by casting l to size_t. In both cases we are guaranteed that l can't be negative hence casting to size_t is fine to do. ../src/rfkill/rfkill.c: In function ‘load_state’: ../src/rfkill/rfkill.c:180:15: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘long unsigned int’ [-Wsign-compare] 180 | if (l < RFKILL_EVENT_SIZE_V1) | ^ ../src/rfkill/rfkill.c: In function ‘run’: ../src/rfkill/rfkill.c:338:23: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘long unsigned int’ [-Wsign-compare] 338 | if (l < RFKILL_EVENT_SIZE_V1) | ^ gcc-11.0.1-0.3.1.el9.x86_64 Related: #1931710 --- src/rfkill/rfkill.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index e2d1a1be5f..6126e9b0c4 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -177,7 +177,7 @@ static int load_state(Context *c, const struct rfkill_event *event) { ssize_t l = write(c->rfkill_fd, &we, sizeof we); if (l < 0) return log_error_errno(errno, "Failed to restore rfkill state for %i: %m", event->idx); - if (l < RFKILL_EVENT_SIZE_V1) + if ((size_t) l < RFKILL_EVENT_SIZE_V1) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Couldn't write rfkill event structure, too short (wrote %zd of %zu bytes).", l, sizeof we); @@ -335,7 +335,7 @@ static int run(int argc, char *argv[]) { break; } - if (l < RFKILL_EVENT_SIZE_V1) + if ((size_t) l < RFKILL_EVENT_SIZE_V1) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read of struct rfkill_event: (%zd < %d)", l, RFKILL_EVENT_SIZE_V1); log_debug("Reading struct rfkill_event: got %zd bytes.", l);