lint fails to be my friend

Michael Henning michi at ptcburp.ptcbu.oz.au
Thu Apr 4 15:30:49 AEST 1991


das at eplunix.UUCP (David Steffens) writes:

>Try the following on your favorite flavor of lint.  The first four if's
>generate "variable may be used before set" complains as expected.
>The fifth if statement does not.  I think it should.  If not, why not??
>Tested on 4.2bsd, 4.3bsd, SunOS4.0.3, SunOS4.1 and RTU5.0 (SysV variant).

>main()
>{
>	int foo;
>	int *bar, *blap, *flap;
>	int baz[10];

>	if (foo == 0)
>		printf("Yikes!\n");
>	if (bar == 0)
>		printf("Egads!\n");
>	if (*blap == 0)
>		printf("Gadzooks!\n");
>	if (flap[2] == 0)
>		printf("Ack!\n");
>	if (baz[2] == 0)
>		printf("Eh?\n");
>	exit(0);
>}

The reason is that 'baz' is an array, and lint cannot check whether an
individual array element has been initialized, since that cannot always
be figured out at compile time. The net effect is that you *never* get
a warning if you use an array element that is not initialized.

In contrast, 'flap' is pointer which is not initialized at the time
it is first used, so you *do* get a warning. The fact that you are indexing
of the pointer has nothing to do with it, you get the same warning if you
replace the fourth test with

	if (flap == 0)
		printf("Ack!\n");
		
							Michi.
-- 
      -m------- Michael Henning			+61 75 950255
    ---mmm----- Pyramid Technology		+61 75 522475 FAX
  -----mmmmm--- Research Park, Bond University	michi at ptcburp.ptcbu.oz.au
-------mmmmmmm- Gold Coast, Q 4229, AUSTRALIA	uunet!munnari!ptcburp.oz!michi



More information about the Comp.bugs.4bsd.ucb-fixes mailing list