From c131b1ed83da70fd739aff90ea3e8e829549ff43 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 15 Jul 2022 22:46:23 +0200 Subject: fix: -Wsign-compare warnings (#336) mixing signed and unsigned types in comparison can end up having unintended results. for example: if (-1 < 1U) printf("true\n"); else printf("false\n"); previously we silenced these warnings, instead just fix them properly via necessary casting, and in cases where the value cannot be negative (e.g width/height members) make them unsigned. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/336 Reviewed-by: explosion-mental --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index a6c4187..877870e 100644 --- a/main.c +++ b/main.c @@ -224,7 +224,7 @@ static bool check_timeouts(int *t) int i = 0, tdiff, tmin = -1; struct timeval now; - while (i < ARRLEN(timeouts)) { + while (i < (int)ARRLEN(timeouts)) { if (timeouts[i].active) { gettimeofday(&now, 0); tdiff = TV_DIFF(&timeouts[i].when, &now); @@ -434,11 +434,11 @@ int nav_button(void) win_cursor_pos(&win, &x, &y); nw = NAV_IS_REL ? win.w * NAV_WIDTH / 100 : NAV_WIDTH; - nw = MIN(nw, (win.w + 1) / 2); + nw = MIN(nw, ((int)win.w + 1) / 2); if (x < nw) return 0; - else if (x < win.w-nw) + else if (x < (int)win.w - nw) return 1; else return 2; @@ -917,7 +917,7 @@ int main(int argc, char *argv[]) const char *name[] = { "image-info", "thumb-info", "key-handler", "win-title" }; const char *s = "/nsxiv/exec/"; - for (i = 0; i < ARRLEN(cmd); i++) { + for (i = 0; i < (int)ARRLEN(cmd); i++) { n = strlen(homedir) + strlen(dsuffix) + strlen(s) + strlen(name[i]) + 1; cmd[i]->cmd = emalloc(n); snprintf(cmd[i]->cmd, n, "%s%s%s%s", homedir, dsuffix, s, name[i]); -- cgit v1.2.3-54-g00ecf