lint: do not warn about comparison 'unsigned <= 0'
Seen in scanners generated by Flex, and about 50 occurrences in the NetBSD src and xsrc tree, all of which are not suspicious of being bugs.
This commit is contained in:
parent
65be30e010
commit
1f92077950
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $ */
|
||||
/* $NetBSD: msg_162.c,v 1.6 2021/09/05 17:49:55 rillig Exp $ */
|
||||
# 3 "msg_162.c"
|
||||
|
||||
// Test for message: comparison of %s with %s, op %s [162]
|
||||
|
@ -23,7 +23,7 @@ left_unsigned(unsigned int ui)
|
|||
if (ui >= 0) {
|
||||
}
|
||||
|
||||
/* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
|
||||
/* before 2021-09-05: comparison of unsigned int with 0, op <= [162] */
|
||||
if (ui <= 0) {
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ right_unsigned(unsigned int ui)
|
|||
if (0 <= ui) {
|
||||
}
|
||||
|
||||
/* expect+1: warning: comparison of 0 with unsigned int, op >= [162] */
|
||||
/* before 2021-09-05: comparison of 0 with unsigned int, op >= [162] */
|
||||
if (0 >= ui) {
|
||||
}
|
||||
}
|
||||
|
@ -97,11 +97,18 @@ compare_operators(unsigned int x)
|
|||
/* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */
|
||||
take_bool(x <= -1);
|
||||
/*
|
||||
* XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint
|
||||
* should not warn about it, just as it doesn't warn about the
|
||||
* inverted condition, which is 'x > 0'.
|
||||
* Before tree.c 1.379 from 2021-09-05, lint warned about
|
||||
* 'unsigned <= 0' as well as '0 >= unsigned'. In all cases where
|
||||
* the programmer knows whether the underlying data type is signed or
|
||||
* unsigned, it is clearer to express the same thought as
|
||||
* 'unsigned == 0', but that's a stylistic issue only.
|
||||
*
|
||||
* Removing this particular case of the warning is not expected to
|
||||
* miss any bugs. The expression 'x <= 0' is equivalent to 'x < 1',
|
||||
* so lint should not warn about it, just as it doesn't warn about
|
||||
* the inverted condition, which is 'x > 0'.
|
||||
*/
|
||||
/* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
|
||||
/* before 2021-09-05: comparison of unsigned int with 0, op <= [162] */
|
||||
take_bool(x <= 0);
|
||||
take_bool(x <= 1);
|
||||
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162]
|
||||
msg_162.c(19): warning: comparison of unsigned int with 0, op < [162]
|
||||
msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162]
|
||||
msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162]
|
||||
msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162]
|
||||
msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162]
|
||||
msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162]
|
||||
msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162]
|
||||
msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162]
|
||||
msg_162.c(92): warning: comparison of unsigned int with negative constant, op < [162]
|
||||
msg_162.c(94): warning: comparison of unsigned int with 0, op < [162]
|
||||
msg_162.c(98): warning: comparison of unsigned int with negative constant, op <= [162]
|
||||
msg_162.c(105): warning: comparison of unsigned int with 0, op <= [162]
|
||||
msg_162.c(109): warning: comparison of unsigned int with negative constant, op > [162]
|
||||
msg_162.c(114): warning: comparison of unsigned int with negative constant, op >= [162]
|
||||
msg_162.c(116): warning: comparison of unsigned int with 0, op >= [162]
|
||||
msg_162.c(120): warning: comparison of unsigned int with negative constant, op == [162]
|
||||
msg_162.c(125): warning: comparison of unsigned int with negative constant, op != [162]
|
||||
msg_162.c(116): warning: comparison of unsigned int with negative constant, op > [162]
|
||||
msg_162.c(121): warning: comparison of unsigned int with negative constant, op >= [162]
|
||||
msg_162.c(123): warning: comparison of unsigned int with 0, op >= [162]
|
||||
msg_162.c(127): warning: comparison of unsigned int with negative constant, op == [162]
|
||||
msg_162.c(132): warning: comparison of unsigned int with negative constant, op != [162]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.86 2021/09/05 16:36:56 rillig Exp $
|
||||
# $NetBSD: Makefile,v 1.87 2021/09/05 17:49:55 rillig Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
|
@ -20,7 +20,6 @@ LINTFLAGS+= -T
|
|||
LOBJS.${PROG}+= ${SRCS:M*.y:.y=.ln}
|
||||
LOBJS.${PROG}+= ${SRCS:M*.l:.l=.ln}
|
||||
LINTFLAGS.scan.c+= -X 107,126,330,331,332,333 # strict bool mode
|
||||
LINTFLAGS.scan.c+= -X 162 # comparison of 'unsigned <= 0'
|
||||
LINTFLAGS.scan.c+= -X 192,214 # due to suppressed bool errors
|
||||
LINTFLAGS.scan.c+= -X 307 # static variable unused
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tree.c,v 1.378 2021/09/05 16:03:55 rillig Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.379 2021/09/05 17:49:55 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.378 2021/09/05 16:03:55 rillig Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.379 2021/09/05 17:49:55 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
@ -4232,7 +4232,7 @@ check_integer_comparison(op_t op, tnode_t *ln, tnode_t *rn)
|
|||
/* comparison of %s with %s, op %s */
|
||||
warning(162, type_name(ln->tn_type),
|
||||
"negative constant", op_name(op));
|
||||
} else if (op == LT || op == GE || (hflag && op == LE)) {
|
||||
} else if (op == LT || op == GE) {
|
||||
/* comparison of %s with %s, op %s */
|
||||
warning(162, type_name(ln->tn_type), "0", op_name(op));
|
||||
}
|
||||
|
@ -4244,7 +4244,7 @@ check_integer_comparison(op_t op, tnode_t *ln, tnode_t *rn)
|
|||
/* comparison of %s with %s, op %s */
|
||||
warning(162, "negative constant",
|
||||
type_name(rn->tn_type), op_name(op));
|
||||
} else if (op == GT || op == LE || (hflag && op == GE)) {
|
||||
} else if (op == GT || op == LE) {
|
||||
/* comparison of %s with %s, op %s */
|
||||
warning(162, "0", type_name(rn->tn_type), op_name(op));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue