diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-10 18:42:46 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-10 18:42:46 +0000 |
commit | c2a54c889d2a7e8d906d049d66a429b198c7d238 (patch) | |
tree | 98e6cf27861e6157690b0b4862809fe1d06ef3f8 /usr.bin/xlint | |
parent | c4f1e971a2d07dc4ca4a80af9e071f6a9728dcb3 (diff) |
Lint now warns about sizeof(term) where the operator is anything other
than unary *, ->, a name, or a string.
Diffstat (limited to 'usr.bin/xlint')
-rw-r--r-- | usr.bin/xlint/lint1/cgram.y | 6 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/err.c | 5 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 3 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 24 |
4 files changed, 30 insertions, 8 deletions
diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 176bdb11dcc..d519b4786a3 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: cgram.y,v 1.16 2005/12/10 17:41:03 cloder Exp $ */ +/* $OpenBSD: cgram.y,v 1.17 2005/12/10 18:42:45 cloder Exp $ */ /* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: cgram.y,v 1.16 2005/12/10 17:41:03 cloder Exp $"; +static char rcsid[] = "$OpenBSD: cgram.y,v 1.17 2005/12/10 18:42:45 cloder Exp $"; #endif #include <stdlib.h> @@ -1545,7 +1545,7 @@ term: } } | T_SIZEOF term %prec T_SIZEOF { - if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL) + if (($$ = $2 == NULL ? NULL : bldszoftrm($2)) != NULL) chkmisc($2, 0, 0, 0, 0, 0, 1); } | T_SIZEOF T_LPARN type_name T_RPARN %prec T_SIZEOF { diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index 86795a81c8d..8320c4d3936 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.12 2005/12/10 17:51:49 cloder Exp $ */ +/* $OpenBSD: err.c,v 1.13 2005/12/10 18:42:45 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.12 2005/12/10 17:51:49 cloder Exp $"; +static char rcsid[] = "$OpenBSD: err.c,v 1.13 2005/12/10 18:42:45 cloder Exp $"; #endif /* number of errors found */ @@ -365,6 +365,7 @@ const char *msgs[] = { "extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */ "right shift of %d-bit quantity by %d bits", /* 310 */ "case ranges are illegal in ANSI C", /* 311 */ + "suspicious operator for sizeof: %s", /* 312 */ }; /* diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index d2022da340d..0d7f2fe9a14 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: externs1.h,v 1.6 2005/12/10 17:51:49 cloder Exp $ */ +/* $OpenBSD: externs1.h,v 1.7 2005/12/10 18:42:45 cloder Exp $ */ /* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */ /* @@ -196,6 +196,7 @@ extern tnode_t *convert(op_t, int, type_t *, tnode_t *); extern void cvtcon(op_t, int, type_t *, val_t *, val_t *); extern const char *tyname(type_t *); extern tnode_t *bldszof(type_t *); +extern tnode_t *bldszoftrm(tnode_t *); extern tnode_t *cast(tnode_t *, type_t *); extern tnode_t *funcarg(tnode_t *, tnode_t *); extern tnode_t *funccall(tnode_t *, tnode_t *); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 4df44bcb1ed..677ef807664 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.21 2005/12/09 04:28:28 cloder Exp $ */ +/* $OpenBSD: tree.c,v 1.22 2005/12/10 18:42:45 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.21 2005/12/09 04:28:28 cloder Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.22 2005/12/10 18:42:45 cloder Exp $"; #endif #include <stdlib.h> @@ -2937,6 +2937,26 @@ foldflt(tnode_t *tn) } /* + * Create a constant node for sizeof(term). + */ +tnode_t * +bldszoftrm(tnode_t *tn) +{ + switch (tn->tn_op) { + case POINT: + case STAR: + case NAME: + case STRING: + break; + default: + warning(312, modtab[tn->tn_op].m_name); + } + + + return bldszof(tn->tn_type); +} + +/* * Create a constant node for sizeof. */ tnode_t * |