lclint-interest message 67

From evs Tue Apr  2 11:57:32 1996
Date: Tue, 2 Apr 96 11:37:26 -0500
From: evs (David Evans)
In-Reply-To: Eric Bloodworth's message of Mon, 01 Apr 1996 17:43:32 -0500 <>
Subject: Re: flags are too blunt an instrument...

Yes, I agree that it would be nice to have a way to set flag-settings
for particular variables, or at least be able to suppress messages
concerning a particular variable.  (No plans to add this to LCLint
anytime soon, though, I'm afraid.)

For the particular example, there are a couple things you could do.

One possibility is to use +loopexec around the loop that defines p[]:

	if (NULL != p) {
		for (i = 0; i < 200; i++) 
			p[i] = i; 
		foo = p[100] + p[10] + p[1] + q[0]; 

This instructs lclint to check the code assuming the body of the loop
always executes.  (In this case it would be better if lclint could
figure out that a loop with compile-time known bounds like this always
executes, but it doesn't attempt to do this.)  Now, p is defined after
the loop, and no use-before-definition error is reported for p.

Without using loopexec, you can use the suppression comments or -usedef
is local ways to make sure only the intended message is suppressed.

For example, if you expect there to be 3 spurious use-before-definitions
errors on the line, do:

		/*@i3@*/ foo = p[100] + p[10] + p[1] + q[0]; 

This means lclint will suppress errors on the line, but will report if
the number of errors suppressed is not equal to 3.

You can also place the /*@-usedef@*/ ... /*@=usedef@*/ comments locally,
to make sure only the indended messages are suppressed:

	foo = /*@-usedef@*/ p[100] + p[10] + p[1] /*@=usedef@*/ + q[0]; 

This suppresses the messages for p between the comments, but on other

--- Dave

Previous Message Next Message Archive Summary LCLint Home Page David Evans
University of Virginia, Computer Science