hiding lint's ravings (was Re: FAQ - malloc array - clarify)

Chris Torek chris at mimsy.umd.edu
Sun Sep 9 06:10:50 AEST 1990


In article <8086 at helios.TAMU.EDU> jdm5548 at diamond.tamu.edu
(James Darrell McCauley) writes:
>How do you professionals deal with insignificant(?) ravings from
>lint (or other high quality C program verifiers) such as
[the bogus `possible pointer alignment problem' messages from malloc]?
>... I can just ignore warnings like this, but those who review
>my code (professors, employers, clients) are not likely to.

Since the warning is due to a bug in lint, those who do not ignore it
are simply compounding the problem.  The real cure is to fix lint.

>By the way, I got this error while using a Sparc under Sun OS 4.0.3c,
>but not under 4.0.3 (which perplexes me).

Looks like someone fixed it, but had to back out the fix (or else 4.0.3
and 4.0.3c were separate development efforts, which is entirely possible).

This happens to be easy to fix as a special case inside lint (add an
`/*ALIGNOK*/' lint-pragma that can be used in <stdXXX.h> files to tag
the special functions malloc and calloc).  A harder one is varargs routines:

	/* used as error(quit, errno, fmt, ...) */

	/* VARARGS3 */
	error(va_alist)	/* note Classic C <varargs.h>, not New C <stdarg.h> */
		va_dcl
	{
		int quit, e;
		char *fmt;
		va_list ap;

		va_start(ap);
		quit = va_arg(ap, int);
		e = va_arg(ap, int);
		fmt = va_arg(ap, int);
		...

One would like lint to verify that the first three arguments are indeed
<int> <int> and <char *> respectively.  (Indeed, since this particular
function behaves like printf, one would also like lint to verify subsequent
arguments the way the 4.3BSD-reno lint [thanks to Arthur Olson] verifies
arguments to printf, fprintf, and sprintf.)

The only solution I have to this is:

	#ifdef lint
	/* VARARGS3 */
	error(quit, e, fmt) int quit, e; char *fmt; { }
	#define error lint_error
	#endif

	... definition of error() as before ...
	#undef error

You must then ignore all `function lint_.* defined but not used' errors.
If you were to use

	#ifdef lint
	/* VARARGS3 */
	error(quit, e, fmt) int quit, e; char *fmt; { }
	#else
	... definition of error() ...
	#endif

then lint would not be able to check the code inside error() itself.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.programmer mailing list