lint enhancement for 4.?bsd (and others?)

Arthur David Olson ado at elsie.UUCP
Mon Sep 24 06:44:26 AEST 1984


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)



More information about the Comp.lang.c mailing list