[net.unix-wizards] lint enhancement for 4.?bsd

ado@elsie.UUCP (Arthur David Olson) (09/22/84)

Had a program today that looked (in part) like this:

	control(counter)
	int	counter;
	{
		if (control > 0)
			--counter;
	}

I was surprised that lint failed to pick up the typo.  So for all you folks
with "lint.c" source:

> ed lint.c
> /case LE:/a
> #ifndef OLDVERSION
>		if (p->in.left->in.op == ICON && p->in.right->in.op == ICON)
>			werror("comparison of constants");
>		else if (p->in.op != EQ && p->in.op != NE)
>			if (ISPTR(p->in.left->in.type) &&
>			    ISFTN(DECREF(p->in.left->in.type)) ||
>			    ISPTR(p->in.right->in.type) &&
>			    ISFTN(DECREF(p->in.right->in.type))	)
>				werror("function address in comparison");
> #endif
.
w
q
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)

ado@elsie.UUCP (Arthur David Olson) (09/23/84)

Another odd lint lapse, shown up by "xfopen" in the 2.10.2 news software:

> FILE *
> xfopen(name, fmode)
> register char *name, *fmode;
> {
> 	register FILE *fp;
> 	.
> 	.
> 	.
> 	if ((fp = fopen(name, fmode)) == NULL) {
> 	.
> 	.
> 	.
> 	}
> 	/* kludge for setuid not being honored for root */
> 	if ((uid == 0) && (duid != 0) && ((fmode == "a") || (fmode == "w")))
> 		chown(name, duid, dgid);
> 	return(fp);
> }

Since YOU can find the bug in the above code by inspection, so can lint.
Adding the check to the other checks added yesterday, we have:

> ed lint.c
> /case LE:/a
> #ifndef OLDVERSION
> 		if (p->in.right->in.op == ICON &&
> 			p->in.right->tn.type == (PTR | CHAR) &&
> 			p->in.right->tn.rval < 0)
> 				werror("comparison with doubly-quoted string");
> 		else if (p->in.left->in.op == ICON &&
> 			p->in.right->in.op == ICON)
> 				werror("comparison of constants");
> 		else if (p->in.op != EQ && p->in.op != NE)
> 			if (ISPTR(p->in.left->in.type) &&
> 			    ISFTN(DECREF(p->in.left->in.type)) ||
> 			    ISPTR(p->in.right->in.type) &&
> 			    ISFTN(DECREF(p->in.right->in.type))	)
> 				werror("function address in comparison");
> #endif
> .
> w
> q

I trust some more knowing person will set things aright if this is worng.
--
UNIX is at AT&T Bell Laboratories trademark.
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)