How can I make splint ignore where I declare my variables?

Do you know how I can make splint ignore where I declare my variables?

I know that in old school you are invited to declare variables right from the beginning of each function, but since I am a bad person, I like to declare things next to where I use them. A good example is setting int i; right before for (i = 0; ...).

Take a very simple example

#include <stdio.h> int main() { printf("Hello splint test\n"); int i; for(i=5;i>0;i--) { printf("%2d...\n",i); } return 0; } 

Here splint and most older c compilers would like to move int i; up one line, or put {} around the declaration and for loop.

And now, to the question, how to disable this check? But keep the other checks that are good?

Thanks Johan


Note 1: I already use gcc warnings (see below) as the first line of defense, and valgrind as the second. But I'm thinking of adding a tire to the list of things that could control my stupidity ;-) But this check is just annoying,

The gcc warnings I use are: -Wall -W -Wextra -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Werror

Note 2: I am aware of potential tolerance problems that may result from such poor behavior. But I feel this enhances readability, since you don't have to jump up and down to search for this type. Ads are more valuable (and we can discuss this in another thread).


Update : A little more information, I put the above code in a file called main.c. The Ubuntu 8.04 platform used and gvim as an editor, and this is the output from the bus when I run it:

 splint +gnuextensions main.c Splint 3.1.1 --- 03 Nov 2006 Command Line: Setting +gnuextensions redundant with current value main.c:8:8: Parse Error. (For help on parse errors, see splint -help parseerrors.) 

And this opens up two more questions that I had not thought of before.

  • "redundant with current value", what is the current value?

  • Why is this an analysis error and not a warning?


Update:: It is possible to plan a bus to support this problem. I have not tried this yet, but still, but I think this is the solution.

+6
c c99 static-analysis lint splint
source share
4 answers

Here's the patch: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20080718/52cc25f6/attachment.obj

You should be able to pass this through patch -p2 if you are in the splint / src directory, and then it should just rebuild.

What from this letter: http://www.cs.virginia.edu/pipermail/splint-discuss/2008-July/001190.html

(Sorry for the interval on this.)

You will find that in the end, if you follow what the thread is related to, but I thought that I would go to the end.

Today, unfortunately, now there is no support from Splint. I would think about coming up and doing a few more if I were not so busy.

Jake

+7
source share

This thread on the Splint mailing list discusses the issue.

The parser seems to be mostly C89 / C90, only the library seems to be C99.

Since the problem is with the parser, you cannot leave by setting flags.

+5
source share

I am not familiar with the tire, but from their FAQ :

The bus is independent of your compiler. It checks the standard C code, in accordance with the ISO C99 specification. Splint supports most, but not all, C99 extensions to ANSI C. Splint supports some of the gcc compiler extensions (if + gnuextensions).

The position of your ad is perfectly consistent with C99, so you may consider this a bug in the bus. Or is this one of the "extensions" not yet supported by the bus. In any case, they may be interested in your feedback. There should be no reason for a C99-compatible lint tool to complain about variable declarations.

+3
source share

Usually, with the bus, if something can be suppressed, he will say: "Suppress it with + thisflag or -thisflag"

You can try splint + gnuextensions foo.c, which includes (most) GNU / GCC extensions, which otherwise the bus would have a problem.

I use the bus almost as often as I use valgrind.

Edit:

As others have said, your run in a parser (not a parser), so the flags really won't help in this case.

+2
source share

All Articles