Subject: bin/34766: Changes for xlint
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <henning.petersen@t-online.de>
List: netbsd-bugs
Date: 10/09/2006 11:20:00
>Number:         34766
>Category:       bin
>Synopsis:       Changes for xlint
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 09 11:20:00 +0000 2006
>Originator:     Henning Petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Add sizeof(term) from OpenBSD;
Missing strg1->st_len=len in function catstrg;
Typos in comments;
>How-To-Repeat:

>Fix:
Index: xlint/lint1/cgram.y
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/cgram.y,v
retrieving revision 1.37
diff -u -r1.37 cgram.y
--- xlint/lint1/cgram.y	12 Jul 2006 20:03:48 -0000	1.37
+++ xlint/lint1/cgram.y	9 Oct 2006 10:01:21 -0000
@@ -1658,7 +1658,7 @@
 		}
 	  }
 	| 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 {
Index: xlint/lint1/decl.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/decl.c,v
retrieving revision 1.35
diff -u -r1.35 decl.c
--- xlint/lint1/decl.c	13 Jul 2006 17:49:29 -0000	1.35
+++ xlint/lint1/decl.c	9 Oct 2006 10:01:24 -0000
@@ -129,7 +129,7 @@
 /*
  * Returns a shared type structure vor arithmetic types and void.
  *
- * It's important do duplicate this structure (using duptyp() or tdupdyp())
+ * It's important to duplicate this structure (using duptyp() or tdupdyp())
  * if it is to be modified (adding qualifiers or anything else).
  */
 type_t *
@@ -164,7 +164,7 @@
 }
 
 /*
- * Returns 1 if the argument is void or an incomplete array,
+ * Returns 1 if the argument is void or a incomplete array,
  * struct, union or enum type.
  */
 int
@@ -810,7 +810,7 @@
 }
 
 /*
- * Get the alignment of the given Type in bits.
+ * Get the alignment of the given type in bits.
  */
 int
 getbound(type_t *tp)
@@ -991,7 +991,7 @@
 		/*
 		 * bit field
 		 *
-		 * only unsigned und signed int are protable bit-field types
+		 * only unsigned and signed int are portable bit-field types
 		 *(at least in ANSI C, in traditional C only unsigned int)
 		 */
 		if (t == CHAR || t == UCHAR || t == SCHAR ||
@@ -1152,8 +1152,8 @@
 
 	if (p2->p_pcnt != 0) {
 		/* left '*' at the end of the list */
-		for (p = p2; p->p_nxt != NULL; p = p->p_nxt)
-			continue;
+		for (p = p2; p->p_nxt != NULL; p = p->p_nxt);
+
 		p->p_nxt = p1;
 		return (p2);
 	} else {
@@ -1180,7 +1180,7 @@
  * Followint 3 functions extend the type of a declarator with
  * pointer, function and array types.
  *
- * The current type is the Type built by deftyp() (dcs->d_type) and
+ * The current type is the type built by deftyp() (dcs->d_type) and
  * pointer, function and array types already added for this
  * declarator. The new type extension is inserted between both.
  */
@@ -1566,7 +1566,7 @@
 			tp->t_enum = getblk(sizeof (enum_t));
 			tp->t_enum->etag = tag;
 		}
-		/* ist unvollstaendiger Typ */
+		/* is incomplete type */
 		setcompl(tp, 1);
 	}
 
@@ -1776,7 +1776,7 @@
 	if (plibflg && llibflg &&
 	    dsym->s_type->t_tspec == FUNC && dsym->s_type->t_proto) {
 		/*
-		 * With both LINTLIBRARY and PROTOLIB the prototyp is
+		 * With both LINTLIBRARY and PROTOLIB the prototype is
 		 * written as a function definition to the output file.
 		 */
 		rval = dsym->s_type->t_subt->t_tspec != VOID;
@@ -2157,7 +2157,7 @@
 			if (dst->t_dim == 0 && src->t_dim != 0) {
 				*dstp = dst = duptyp(dst);
 				dst->t_dim = src->t_dim;
-				/* now a complete Typ */
+				/* now a complete type */
 				setcompl(dst, 0);
 			}
 		} else if (dst->t_tspec == FUNC) {
@@ -2236,7 +2236,7 @@
  * Does some checks for lint directives which apply to functions.
  * Processes arguments in old style function definitions which default
  * to int.
- * Checks compatiblility of old style function definition with previous
+ * Checks compatibility of old style function definition with previous
  * prototype.
  */
 void
@@ -2307,7 +2307,7 @@
 	}
 
 	/*
-	 * print a warning for each argument off an old style function
+	 * print a warning for each argument of an old style function
 	 * definition which defaults to int
 	 */
 	for (arg = args; arg != NULL; arg = arg->s_nxt) {
@@ -2320,7 +2320,7 @@
 	}
 
 	/*
-	 * If this is an old style function definition and a prototyp
+	 * If this is an old style function definition and a prototype
 	 * exists, compare the types of arguments.
 	 */
 	if (funcsym->s_osdef && funcsym->s_type->t_proto) {
@@ -2590,7 +2590,7 @@
 
 /*
  * Print an error or a warning if the symbol cant be initialized due
- * to type/storage class. Returnvalue is 1 if an error has been
+ * to type/storage class. Return value is 1 if an error has been
  * detected.
  */
 static int
Index: xlint/lint1/emit1.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/emit1.c,v
retrieving revision 1.16
diff -u -r1.16 emit1.c
--- xlint/lint1/emit1.c	24 Sep 2005 15:30:35 -0000	1.16
+++ xlint/lint1/emit1.c	9 Oct 2006 10:01:24 -0000
@@ -429,8 +429,7 @@
 	/* informations about arguments */
 	for (n = 1; n <= narg; n++) {
 		/* the last argument is the top one in the tree */
-		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
-			continue;
+		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ;
 		arg = arg->tn_left;
 		if (arg->tn_op == CON) {
 			if (isityp(t = arg->tn_type->t_tspec)) {
@@ -471,8 +470,7 @@
 	outint(narg);
 	for (n = 1; n <= narg; n++) {
 		/* the last argument is the top one in the tree */
-		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
-			continue;
+		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right);
 		outtype(arg->tn_left->tn_type);
 	}
 	/* expected type of return value */
@@ -481,7 +479,7 @@
 
 /*
  * extracts potential format specifiers for printf() and scanf() and
- * writes them, enclosed in "" and qouted if necessary, to the output buffer
+ * writes them, enclosed in "" and quoted if necessary, to the output buffer
  */
 static void
 outfstrg(strg_t *strg)
Index: xlint/lint1/err.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/err.c,v
retrieving revision 1.29
diff -u -r1.29 err.c
--- xlint/lint1/err.c	2 Jan 2005 10:40:49 -0000	1.29
+++ xlint/lint1/err.c	9 Oct 2006 10:01:25 -0000
@@ -381,6 +381,7 @@
 	"compound literals are a C9X/GCC extension",		      /* 319 */
 	"({ }) is a GCC extension",				      /* 320 */
 	"array initializer with designators is a C9X feature",	      /* 321 */
+	"suspicious operator for sizeof: %s"			      /* 322 */
 };
 
 /*
Index: xlint/lint1/externs1.h
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/externs1.h,v
retrieving revision 1.21
diff -u -r1.21 externs1.h
--- xlint/lint1/externs1.h	7 Apr 2005 16:28:40 -0000	1.21
+++ xlint/lint1/externs1.h	9 Oct 2006 10:01:25 -0000
@@ -197,6 +197,7 @@
 extern	tnode_t	*promote(op_t, int, tnode_t *);
 extern	tnode_t	*convert(op_t, int, type_t *, tnode_t *);
 extern	void	cvtcon(op_t, int, type_t *, val_t *, val_t *);
+extern	tnode_t	*bldszoftrm(tnode_t *);
 extern	tnode_t	*bldszof(type_t *);
 extern	tnode_t	*cast(tnode_t *, type_t *);
 extern	tnode_t	*funcarg(tnode_t *, tnode_t *);
Index: xlint/lint1/func.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/func.c,v
retrieving revision 1.22
diff -u -r1.22 func.c
--- xlint/lint1/func.c	24 Sep 2005 15:30:35 -0000	1.22
+++ xlint/lint1/func.c	9 Oct 2006 10:01:27 -0000
@@ -62,7 +62,7 @@
 int	rchflg;
 
 /*
- * In conjunction with reached ontrols printing of "fallthrough on ..."
+ * In conjunction with reached controls printing of "fallthrough on ..."
  * warnings.
  * Reset by each statement and set by FALLTHROUGH, switch (switch1())
  * and case (label()).
@@ -110,13 +110,13 @@
 pos_t	scflpos;
 
 /*
- * Are both plibflg and llibflg set, prototypes are writen as function
+ * Are both plibflg and llibflg set, prototypes are written as function
  * definitions to the output file.
  */
 int	plibflg;
 
 /*
- * Nonzero means that no warnings about constands in conditional
+ * Nonzero means that no warnings about constants in conditional
  * context are printed.
  */
 int	ccflg;
@@ -201,7 +201,7 @@
  * Called after a function declaration which introduces a function definition
  * and before an (optional) old style argument declaration list.
  *
- * Puts all symbols declared in the Prototype or in an old style argument
+ * Puts all symbols declared in the prototype or in an old style argument
  * list back to the symbol table.
  *
  * Does the usual checking of storage class, type (return value),
@@ -428,8 +428,7 @@
 	case T_CASE:
 
 		/* find the stack entry for the innermost switch statement */
-		for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
-			continue;
+		for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ;
 
 		if (ci == NULL) {
 			/* case not in switch */
@@ -501,8 +500,7 @@
 	case T_DEFAULT:
 
 		/* find the stack entry for the innermost switch statement */
-		for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt)
-			continue;
+		for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt);
 
 		if (ci == NULL) {
 			/* default outside switch */
@@ -942,8 +940,7 @@
 {
 	cstk_t	*ci;
 
-	for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt)
-		continue;
+	for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) ;
 
 	if (ci == NULL) {
 		/* continue outside loop */
@@ -968,8 +965,7 @@
 	cstk_t	*ci;
 	op_t	op;
 
-	for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt)
-		continue;
+	for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt);
 
 	if (tn != NULL) {
 		ci->c_retval = 1;
Index: xlint/lint1/lint1.h
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/lint1.h,v
retrieving revision 1.19
diff -u -r1.19 lint1.h
--- xlint/lint1/lint1.h	24 Sep 2005 15:30:35 -0000	1.19
+++ xlint/lint1/lint1.h	9 Oct 2006 10:01:27 -0000
@@ -104,7 +104,7 @@
  * Structures of type str_t uniqely identify structures. This can't
  * be done in structures of type type_t, because these are copied
  * if they must be modified. So it would not be possible to check
- * if to structures are identical by comparing the pointers to
+ * if two structures are identical by comparing the pointers to
  * the type structures.
  *
  * The typename is used if the structure is unnamed to identify
Index: xlint/lint1/scan.l
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/scan.l,v
retrieving revision 1.34
diff -u -r1.34 scan.l
--- xlint/lint1/scan.l	22 Mar 2006 02:14:03 -0000	1.34
+++ xlint/lint1/scan.l	9 Oct 2006 10:01:29 -0000
@@ -514,7 +514,7 @@
 		warning(252);
 
 	/*
-	 * If the value is to big for the current type, we must choose
+	 * If the value is too big for the current type, we must choose
 	 * another type.
 	 */
 	ansiu = 0;
@@ -649,7 +649,7 @@
 }
 
 /*
- * Convert a string representing a floating point value into its interal
+ * Convert a string representing a floating point value into its integral
  * representation. Type and value are returned in yylval. fcon()
  * (and yylex()) returns T_CON.
  * XXX Currently it is not possible to convert constants of type
@@ -958,8 +958,7 @@
 	static	int first = 1;
 
 	/* Go to first non-whitespace after # */
-	for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++)
-		continue;
+	for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++);
 
 	if (!isdigit((unsigned char)c)) {
 	error:
@@ -972,8 +971,8 @@
 		goto error;
 	if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0')
 		goto error;
-	while ((c = *cp++) == ' ' || c == '\t')
-		continue;
+	while ((c = *cp++) == ' ' || c == '\t');
+
 	if (c != '\0') {
 		if (c != '"')
 			goto error;
@@ -984,8 +983,8 @@
 			goto error;
 		if ((fnl = cp++ - fn) > PATH_MAX)
 			goto error;
-		while ((c = *cp++) == ' ' || c == '\t')
-			continue;
+		while ((c = *cp++) == ' ' || c == '\t');
+
 #if 0
 		if (c != '\0')
 			warning("extra character(s) after directive");
@@ -1067,8 +1066,8 @@
 	eoc = 0;
 
 	/* Skip white spaces after the start of the comment */
-	while ((c = inpc()) != EOF && isspace(c))
-		continue;
+	while ((c = inpc()) != EOF && isspace(c));
+
 
 	/* Read the potential keyword to keywd */
 	l = 0;
@@ -1145,8 +1144,7 @@
 		/* // comments only supported in C99 */
 		(void)gnuism(312, tflag ? "traditional" : "ANSI");
 
-	while ((c = inpc()) != EOF && c != '\n')
-		continue;
+	while ((c = inpc()) != EOF && c != '\n');
 }
 
 /*
Index: xlint/lint1/tree.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint1/tree.c,v
retrieving revision 1.42
diff -u -r1.42 tree.c
--- xlint/lint1/tree.c	22 Mar 2006 02:08:55 -0000	1.42
+++ xlint/lint1/tree.c	9 Oct 2006 10:01:33 -0000
@@ -561,7 +561,7 @@
 
 	/*
 	 * Apply class conversions to the left operand, but only if its
-	 * value is needed or it is compaired with null.
+	 * value is needed or it is compared with null.
 	 */
 	if (mp->m_vctx || mp->m_tctx)
 		ln = cconv(ln);
@@ -618,7 +618,7 @@
 
 	/*
 	 * Check types for compatibility with the operation and mutual
-	 * compatibility. Return if there are serios problems.
+	 * compatibility. Return if there are serious problems.
 	 */
 	if (!typeok(op, 0, ln, rn))
 		return (NULL);
@@ -763,7 +763,7 @@
 
 /*
  * Perform most type checks. First the types are checked using
- * informations from modtab[]. After that it is done by hand for
+ * information from modtab[]. After that it is done by hand for
  * more complicated operators and type combinations.
  *
  * If the types are ok, typeok() returns 1, otherwise 0.
@@ -816,11 +816,9 @@
 		 * For these operations we need the types before promotion
 		 * and balancing.
 		 */
-		for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left)
-			continue;
+		for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left);
 		olt = tn->tn_type->t_tspec;
-		for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left)
-			continue;
+		for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left);
 		ort = tn->tn_type->t_tspec;
 	}
 
@@ -828,7 +826,7 @@
 	case POINT:
 		/*
 		 * Most errors required by ANSI C are reported in strmemb().
-		 * Here we only must check for totaly wrong things.
+		 * Here we only must check for totally wrong things.
 		 */
 		if (lt == FUNC || lt == VOID || ltp->t_isfield ||
 		    ((lt != STRUCT && lt != UNION) && !ln->tn_lvalue)) {
@@ -975,14 +973,14 @@
 		 * 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)
@@ -995,7 +993,7 @@
 				/* negative shift */
 				warning(121);
 			} else if ((uint64_t)rn->tn_val->v_quad == size(lt)) {
-				/* shift equal to size fo object */
+				/* shift equal to size of object */
 				warning(267);
 			} else if ((uint64_t)rn->tn_val->v_quad > size(lt)) {
 				/* shift greater than size of object */
@@ -1121,7 +1119,7 @@
 		goto assign;
 	case SHRASS:
 		if (pflag && !isutyp(lt) && !(tflag && isutyp(rt))) {
-			/* bitwise operation on s.v. possibly nonportabel */
+			/* bitwise operation on s.v. possibly nonportable */
 			warning(117);
 		}
 		goto assign;
@@ -1767,7 +1765,7 @@
 }
 
 /*
- * Print warnings for conversions of integer types which my cause
+ * Print warnings for conversions of integer types which may cause
  * problems.
  */
 /* ARGSUSED */
@@ -2934,6 +2932,26 @@
 }
 
 /*
+ * 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(322, modtab[tn->tn_op].m_name);
+	}
+
+
+	return bldszof(tn->tn_type);
+}
+
+/*
  * Create a constant node for sizeof.
  */
 tnode_t *
@@ -3154,8 +3172,7 @@
 		 * The rightmost argument is at the top of the argument
 		 * subtree.
 		 */
-		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right)
-			continue;
+		for (i = narg, arg = args; i > n; i--, arg = arg->tn_right);
 
 		/* some things which are always not allowd */
 		if ((at = arg->tn_left->tn_type->t_tspec) == VOID) {
@@ -3714,7 +3731,7 @@
 }
 
 /*
- * Takes an expression an returns 0 if this expression can be used
+ * Takes an expression and returns 0 if this expression can be used
  * for static initialisation, otherwise -1.
  *
  * Constant initialisation expressions must be constant or an address
@@ -3825,6 +3842,7 @@
 		free(strg2->st_wcp);
 	}
 	free(strg2);
+	strg1->st_len = len;
 
 	return (strg1);
 }
Index: xlint/lint2/main2.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint2/main2.c,v
retrieving revision 1.7
diff -u -r1.7 main2.c
--- xlint/lint2/main2.c	20 Jun 2004 22:20:17 -0000	1.7
+++ xlint/lint2/main2.c	9 Oct 2006 10:01:33 -0000
@@ -137,8 +137,7 @@
 			Fflag = 1;
 			break;
 		case 'l':
-			for (i = 0; libs[i] != NULL; i++)
-				continue;
+			for (i = 0; libs[i] != NULL; i++);
 			libs = xrealloc(libs, (i + 2) * sizeof (char *));
 			libs[i] = xstrdup(optarg);
 			libs[i + 1] = NULL;
Index: xlint/lint2/read.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/lint2/read.c,v
retrieving revision 1.18
diff -u -r1.18 read.c
--- xlint/lint2/read.c	22 Mar 2006 16:16:59 -0000	1.18
+++ xlint/lint2/read.c	9 Oct 2006 10:01:34 -0000
@@ -1171,8 +1171,8 @@
 	 * XXX this entry should be put at the beginning of the list to
 	 * avoid to process the same symbol twice.
 	 */
-	for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link)
-		continue;
+	for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link);
+
 	nhte->h_link = xmalloc(sizeof (hte_t));
 	nhte = nhte->h_link;
 	nhte->h_name = hte->h_name;
Index: xlint/xlint/xlint.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xlint/xlint/xlint.c,v
retrieving revision 1.37
diff -u -r1.37 xlint.c
--- xlint/xlint/xlint.c	2 Jun 2005 04:38:46 -0000	1.37
+++ xlint/xlint/xlint.c	9 Oct 2006 10:01:35 -0000
@@ -157,8 +157,7 @@
 	int	i;
 
 	olst = *lstp;
-	for (i = 0; olst[i] != NULL; i++)
-		continue;
+	for (i = 0; olst[i] != NULL; i++);
 	lst = xrealloc(olst, (i + 2) * sizeof (char *));
 	lst[i] = s;
 	lst[i + 1] = NULL;
@@ -179,10 +178,8 @@
 	char	**dest, **odest;
 
 	odest = *destp;
-	for (i = 0; odest[i] != NULL; i++)
-		continue;
-	for (k = 0; src[k] != NULL; k++)
-		continue;
+	for (i = 0; odest[i] != NULL; i++);
+	for (k = 0; src[k] != NULL; k++);
 	dest = xrealloc(odest, (i + k + 1) * sizeof (char *));
 	for (k = 0; src[k] != NULL; k++)
 		dest[i + k] = xstrdup(src[k]);
@@ -196,8 +193,7 @@
 	char	*s;
 	int	i;
 
-	for (i = 0; (*lstp)[i] != NULL; i++)
-		continue;
+	for (i = 0; (*lstp)[i] != NULL; i++);
 	while (i-- > 0) {
 		s = (*lstp)[i];
 		(*lstp)[i] = NULL;