Module Name: src Committed By: rillig Date: Sat Oct 9 21:56:12 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_230.c msg_230.exp src/usr.bin/xlint/lint1: err.c tree.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_230.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_230.exp cvs rdiff -u -r1.145 -r1.146 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.384 -r1.385 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_230.c diff -u src/tests/usr.bin/xlint/lint1/msg_230.c:1.8 src/tests/usr.bin/xlint/lint1/msg_230.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_230.c:1.8 Sat Aug 28 15:25:10 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.c Sat Oct 9 21:56:12 2021 @@ -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 @@ compare_plain_char(char c) 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 @@ void 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 @@ compare_lt(char c) * 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 @@ compare_lt(char c) */ 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; } Index: src/tests/usr.bin/xlint/lint1/msg_230.exp diff -u src/tests/usr.bin/xlint/lint1/msg_230.exp:1.7 src/tests/usr.bin/xlint/lint1/msg_230.exp:1.8 --- src/tests/usr.bin/xlint/lint1/msg_230.exp:1.7 Sat Aug 28 15:25:10 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.exp Sat Oct 9 21:56:12 2021 @@ -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] Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.145 src/usr.bin/xlint/lint1/err.c:1.146 --- src/usr.bin/xlint/lint1/err.c:1.145 Sun Sep 12 16:28:45 2021 +++ src/usr.bin/xlint/lint1/err.c Sat Oct 9 21:56:12 2021 @@ -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 char *const msgs[] = { "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 */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.384 src/usr.bin/xlint/lint1/tree.c:1.385 --- src/usr.bin/xlint/lint1/tree.c:1.384 Sat Oct 9 20:03:20 2021 +++ src/usr.bin/xlint/lint1/tree.c Sat Oct 9 21:56:12 2021 @@ -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 @@ check_integer_comparison(op_t op, tnode_ 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) {