summaryrefslogtreecommitdiff
path: root/usr.bin/xlint
diff options
context:
space:
mode:
authorChad Loder <cloder@cvs.openbsd.org>2005-11-23 00:12:14 +0000
committerChad Loder <cloder@cvs.openbsd.org>2005-11-23 00:12:14 +0000
commit282fd585c259b44187bc536dcf883d0c98d57de9 (patch)
tree53ff836955e2962224c1dc769b6219eb6be25e4c /usr.bin/xlint
parentf6dbd7c62a4efddabbee50c0518cbfb8976c8a06 (diff)
Warn on a right shift of an N-bit quantity by >= N bits. OK millert,
deraadt
Diffstat (limited to 'usr.bin/xlint')
-rw-r--r--usr.bin/xlint/lint1/err.c5
-rw-r--r--usr.bin/xlint/lint1/tree.c20
2 files changed, 18 insertions, 7 deletions
diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c
index 22d93d232db..b54d7475cb8 100644
--- a/usr.bin/xlint/lint1/err.c
+++ b/usr.bin/xlint/lint1/err.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: err.c,v 1.9 2005/11/21 18:28:24 cloder Exp $ */
+/* $OpenBSD: err.c,v 1.10 2005/11/23 00:12:13 cloder Exp $ */
/* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */
/*
@@ -33,7 +33,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: err.c,v 1.9 2005/11/21 18:28:24 cloder Exp $";
+static char rcsid[] = "$OpenBSD: err.c,v 1.10 2005/11/23 00:12:13 cloder Exp $";
#endif
/* number of errors found */
@@ -363,6 +363,7 @@ const char *msgs[] = {
"static variable %s set but not used", /* 307 */
"", /* 308 */
"extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */
+ "right shift of %d-bit quantity by %d bits", /* 310 */
};
/*
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index 50c8176683c..e0848e86f14 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.10 2005/11/21 18:28:24 cloder Exp $ */
+/* $OpenBSD: tree.c,v 1.11 2005/11/23 00:12:13 cloder Exp $ */
/* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */
/*
@@ -33,7 +33,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: tree.c,v 1.10 2005/11/21 18:28:24 cloder Exp $";
+static char rcsid[] = "$OpenBSD: tree.c,v 1.11 2005/11/23 00:12:13 cloder Exp $";
#endif
#include <stdlib.h>
@@ -935,20 +935,25 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
warning(118, mp->m_name);
}
}
+
+ /* questionable right shift of %d-bit quantity by %d bits */
+ if (rn->tn_op == CON && size(olt) <= rn->tn_val->v_quad)
+ warning(310, size(olt), rn->tn_val->v_quad);
+
goto shift;
case SHL:
/*
* ANSI C does not perform balancing for shift operations,
* but traditional C does. If the width of the right operand
* is greather than the width of the left operand, than in
- * traditional C the left operand would be extendet to the
+ * traditional C the left operand would be extended to the
* width of the right operand. For SHL this may result in
* different results.
*/
if (psize(lt) < psize(rt)) {
/*
* XXX If both operands are constant make sure
- * that there is really a differencs between
+ * that there is really a difference between
* ANSI C and traditional C.
*/
if (hflag)
@@ -961,7 +966,7 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
/* negative shift */
warning(121);
} else if ((u_quad_t)rn->tn_val->v_quad == size(lt)) {
- /* shift equal to size fo object */
+ /* shift equal to size of object */
warning(267);
} else if ((u_quad_t)rn->tn_val->v_quad > size(lt)) {
/* shift greater than size of object */
@@ -1088,6 +1093,11 @@ typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn)
/* bitwise operation on s.v. possibly nonportabel */
warning(117);
}
+
+ /* questionable right shift of %d-bit quantity by %d bits */
+ if (rn->tn_op == CON && size(olt) <= rn->tn_val->v_quad)
+ warning(310, size(olt), rn->tn_val->v_quad);
+
goto assign;
case ANDASS:
case XORASS: