From 2f4e803874067b1b6b8c372794b83ee2fc9fbf3a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 5 Apr 2020 19:53:13 -0700 Subject: warning cleanup: unsigned < 0 comparisons. This is the fourth round of an effort to enable GCC's -Wextra option. Instances of code that test whether an unsigned quantity is negative are repaired. Real bugs are found. * itypes.c (c_u32, c_uint, c_ulong): Remove useless comparison for < 0 that was copy-pasted from the signed cases. * linenoise/linenoise.c (show_help, edit): Do not test the return value of the getch_fn callback for negative. It returns wint_t, which may be unsigned. Test for the WEOF value. This is a bug because since the original comparison is always false, the code fails to catch the WEOF return. --- itypes.c | 6 +++--- linenoise/linenoise.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/itypes.c b/itypes.c index d5821638..ba8705e2 100644 --- a/itypes.c +++ b/itypes.c @@ -90,7 +90,7 @@ i32_t c_i32(val n, val self) u32_t c_u32(val n, val self) { uint_ptr_t v = c_unum(n); - if (v < 0 || v > 0xFFFFFFFF) + if (v > 0xFFFFFFFF) uw_throwf(error_s, lit("~a: value ~s is out of unsigned 32 bit range"), self, n, nao); return v; @@ -228,7 +228,7 @@ int c_int(val n, val self) unsigned int c_uint(val n, val self) { uint_ptr_t v = c_unum(n); - if (v < 0 || v > UINT_MAX) + if (v > UINT_MAX) uw_throwf(error_s, lit("~a: value ~s is out of unsigned int range"), self, n, nao); return v; @@ -253,7 +253,7 @@ unsigned long c_ulong(val n, val self) { #if SIZEOF_LONG <= SIZEOF_PTR uint_ptr_t v = c_unum(n); - if (v < 0 || v > ULONG_MAX) + if (v > ULONG_MAX) uw_throwf(error_s, lit("~a: value ~s is out of unsigned long range"), self, n, nao); return v; diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 998314cf..83a08ec7 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -840,14 +840,14 @@ static void show_help(lino_t *l) break; continue; case ESC: - if ((seq[0] = lino_os.getch_fn(l->tty_ifs)) < 0) + if ((seq[0] = lino_os.getch_fn(l->tty_ifs)) == WEOF) break; - if ((seq[1] = lino_os.getch_fn(l->tty_ifs)) < 0) + if ((seq[1] = lino_os.getch_fn(l->tty_ifs)) == WEOF) break; if (seq[0] == '[') { if (seq[1] >= '0' && seq[1] <= '9') { - if ((seq[2] = lino_os.getch_fn(l->tty_ifs)) < 0) + if ((seq[2] = lino_os.getch_fn(l->tty_ifs)) == WEOF) break; if (seq[2] == '~') { switch(seq[1]) { @@ -2261,7 +2261,7 @@ static int edit(lino_t *l, const wchar_t *prompt) break; } - if (c < 0) + if (c == WEOF) goto out; if (c == 0) continue; -- cgit v1.2.3