Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: add more details to warning about ...



details:   https://anonhg.NetBSD.org/src/rev/3956a200a3c3
branches:  trunk
changeset: 1024097:3956a200a3c3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 09 21:56:12 2021 +0000

description:
lint: add more details to warning about nonportable character comparison

Especially when macros are involved, this makes it easier to see that
there is a real problem.

Seen in bin/sh/expand.c:273, where a plain char is compared to numbers
larger than 127.

diffstat:

 tests/usr.bin/xlint/lint1/msg_230.c   |  40 +++++++++++++++++-----------------
 tests/usr.bin/xlint/lint1/msg_230.exp |  36 +++++++++++++++---------------
 usr.bin/xlint/lint1/err.c             |   6 ++--
 usr.bin/xlint/lint1/tree.c            |  21 ++++++++++++------
 4 files changed, 55 insertions(+), 48 deletions(-)

diffs (229 lines):

diff -r a0957026e838 -r 3956a200a3c3 tests/usr.bin/xlint/lint1/msg_230.c
--- a/tests/usr.bin/xlint/lint1/msg_230.c       Sat Oct 09 21:31:36 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.c       Sat Oct 09 21:56:12 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_230.c,v 1.8 2021/08/28 15:25:10 rillig Exp $       */
+/*     $NetBSD: msg_230.c,v 1.9 2021/10/09 21:56:12 rillig Exp $       */
 # 3 "msg_230.c"
 
-// Test for message: nonportable character comparison, op %s [230]
+// Test for message: nonportable character comparison '%s %d' [230]
 
 /* lint1-flags: -S -g -p -w */
 /* lint1-only-if: schar */
@@ -19,26 +19,26 @@
 void
 compare_plain_char(char c)
 {
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -129' [230] */
        if (c == -129)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -128' [230] */
        if (c == -128)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -1' [230] */
        if (c == -1)
                return;
        if (c == 0)
                return;
        if (c == 127)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 128' [230] */
        if (c == 128)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 255' [230] */
        if (c == 255)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 256' [230] */
        if (c == 256)
                return;
 }
@@ -46,26 +46,26 @@
 void
 compare_plain_char_yoda(char c)
 {
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -129' [230] */
        if (-129 == c)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -128' [230] */
        if (-128 == c)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== -1' [230] */
        if (-1 == c)
                return;
        if (0 == c)
                return;
        if (127 == c)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 128' [230] */
        if (128 == c)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 255' [230] */
        if (255 == c)
                return;
-       /* expect+1: warning: nonportable character comparison, op == [230] */
+       /* expect+1: warning: nonportable character comparison '== 256' [230] */
        if (256 == c)
                return;
 }
@@ -74,10 +74,10 @@
 compare_lt(char c)
 {
 
-       /* expect+1: warning: nonportable character comparison, op > [230] */
+       /* expect+1: warning: nonportable character comparison '> -2' [230] */
        if (c > -2)
                return;
-       /* expect+1: warning: nonportable character comparison, op >= [230] */
+       /* expect+1: warning: nonportable character comparison '>= -1' [230] */
        if (c >= -1)
                return;
 
@@ -85,7 +85,7 @@
         * XXX: The following two comparisons have the same effect, yet lint
         * only warns about one of them.
         */
-       /* expect+1: warning: nonportable character comparison, op > [230] */
+       /* expect+1: warning: nonportable character comparison '> -1' [230] */
        if (c > -1)
                return;
        /*
@@ -101,14 +101,14 @@
         */
        if (c > 127)
                return;
-       /* expect+1: warning: nonportable character comparison, op >= [230] */
+       /* expect+1: warning: nonportable character comparison '>= 128' [230] */
        if (c >= 128)
                return;
 
-       /* expect+1: warning: nonportable character comparison, op > [230] */
+       /* expect+1: warning: nonportable character comparison '> 128' [230] */
        if (c > 128)
                return;
-       /* expect+1: warning: nonportable character comparison, op >= [230] */
+       /* expect+1: warning: nonportable character comparison '>= 129' [230] */
        if (c >= 129)
                return;
 }
diff -r a0957026e838 -r 3956a200a3c3 tests/usr.bin/xlint/lint1/msg_230.exp
--- a/tests/usr.bin/xlint/lint1/msg_230.exp     Sat Oct 09 21:31:36 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.exp     Sat Oct 09 21:56:12 2021 +0000
@@ -1,18 +1,18 @@
-msg_230.c(23): warning: nonportable character comparison, op == [230]
-msg_230.c(26): warning: nonportable character comparison, op == [230]
-msg_230.c(29): warning: nonportable character comparison, op == [230]
-msg_230.c(36): warning: nonportable character comparison, op == [230]
-msg_230.c(39): warning: nonportable character comparison, op == [230]
-msg_230.c(42): warning: nonportable character comparison, op == [230]
-msg_230.c(50): warning: nonportable character comparison, op == [230]
-msg_230.c(53): warning: nonportable character comparison, op == [230]
-msg_230.c(56): warning: nonportable character comparison, op == [230]
-msg_230.c(63): warning: nonportable character comparison, op == [230]
-msg_230.c(66): warning: nonportable character comparison, op == [230]
-msg_230.c(69): warning: nonportable character comparison, op == [230]
-msg_230.c(78): warning: nonportable character comparison, op > [230]
-msg_230.c(81): warning: nonportable character comparison, op >= [230]
-msg_230.c(89): warning: nonportable character comparison, op > [230]
-msg_230.c(105): warning: nonportable character comparison, op >= [230]
-msg_230.c(109): warning: nonportable character comparison, op > [230]
-msg_230.c(112): warning: nonportable character comparison, op >= [230]
+msg_230.c(23): warning: nonportable character comparison '== -129' [230]
+msg_230.c(26): warning: nonportable character comparison '== -128' [230]
+msg_230.c(29): warning: nonportable character comparison '== -1' [230]
+msg_230.c(36): warning: nonportable character comparison '== 128' [230]
+msg_230.c(39): warning: nonportable character comparison '== 255' [230]
+msg_230.c(42): warning: nonportable character comparison '== 256' [230]
+msg_230.c(50): warning: nonportable character comparison '== -129' [230]
+msg_230.c(53): warning: nonportable character comparison '== -128' [230]
+msg_230.c(56): warning: nonportable character comparison '== -1' [230]
+msg_230.c(63): warning: nonportable character comparison '== 128' [230]
+msg_230.c(66): warning: nonportable character comparison '== 255' [230]
+msg_230.c(69): warning: nonportable character comparison '== 256' [230]
+msg_230.c(78): warning: nonportable character comparison '> -2' [230]
+msg_230.c(81): warning: nonportable character comparison '>= -1' [230]
+msg_230.c(89): warning: nonportable character comparison '> -1' [230]
+msg_230.c(105): warning: nonportable character comparison '>= 128' [230]
+msg_230.c(109): warning: nonportable character comparison '> 128' [230]
+msg_230.c(112): warning: nonportable character comparison '>= 129' [230]
diff -r a0957026e838 -r 3956a200a3c3 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Oct 09 21:31:36 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Oct 09 21:56:12 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.145 2021/09/12 16:28:45 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.146 2021/10/09 21:56:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.145 2021/09/12 16:28:45 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.146 2021/10/09 21:56:12 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -284,7 +284,7 @@
        "const object %s should have initializer",                    /* 227 */
        "function cannot return const or volatile object",            /* 228 */
        "converting '%s' to '%s' is questionable",                    /* 229 */
-       "nonportable character comparison, op %s",                    /* 230 */
+       "nonportable character comparison '%s %d'",                   /* 230 */
        "argument '%s' unused in function '%s'",                      /* 231 */
        "label '%s' unused in function '%s'",                         /* 232 */
        "struct %s never defined",                                    /* 233 */
diff -r a0957026e838 -r 3956a200a3c3 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Oct 09 21:31:36 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Oct 09 21:56:12 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.384 2021/10/09 20:03:20 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.385 2021/10/09 21:56:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.384 2021/10/09 20:03:20 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.385 2021/10/09 21:56:12 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4255,12 +4255,19 @@
        if (!is_integer(lt) || !is_integer(rt))
                return;
 
-       if ((hflag || pflag) && ((lt == CHAR && is_out_of_char_range(rn)) ||
-                                (rt == CHAR && is_out_of_char_range(ln)))) {
-               /* nonportable character comparison, op %s */
-               warning(230, op_name(op));
-               return;
+       if (hflag || pflag) {
+               if (lt == CHAR && is_out_of_char_range(rn)) {
+                       /* nonportable character comparison '%s %d' */
+                       warning(230, op_name(op), (int)rn->tn_val->v_quad);
+                       return;
+               }
+               if (rt == CHAR && is_out_of_char_range(ln)) {
+                       /* nonportable character comparison '%s %d' */
+                       warning(230, op_name(op), (int)ln->tn_val->v_quad);
+                       return;
+               }
        }
+
        if (is_uinteger(lt) && !is_uinteger(rt) &&
            rn->tn_op == CON && rn->tn_val->v_quad <= 0) {
                if (rn->tn_val->v_quad < 0) {



Home | Main Index | Thread Index | Old Index