lint suggestion

Richard A. O'Keefe ok at quintus.UUCP
Mon Feb 8 16:15:13 AEST 1988


There's a feature missing from every Lint I've tried, which would be
very useful, and should be easy to add (if I had sources, I'd be doing
it right now).  Consider the stdio functions
	fscanf( FILE *f, const char *f, ...)
	sscanf( char *b, const char *f, ...)
	 scanf(          const char *f, ...)
	fprintf(FILE *f, const char *f, ...)
	sprintf(char *b, const char *f, ...)
	 printf(         const char *f, ...)
In each of these functions, the format argument is almost always a literal,
and it is very easy by inspecting this literal to determine how many
arguments should follow and what their types should be.  Why not check
that the arguments are consistent with the format?  (This would also help
to catch unimplemented format items; I wouldn't be surprised to find that
some of my old programs still contain %r.)

What got me thinking about this was seeing a program which did

	unsigned short x;
	...
	printf("...%ld...", ..., x, ...);

and which Lint had no objection to at all.  I've used a Fortran compiler
which caught this kind of mistake at compile time, and format errors were
no less common than some of the other things Lint catches.



More information about the Comp.lang.c mailing list