Menu

#19 False positive for "variable is declared but never used"

open
nobody
None
5
2011-06-27
2011-06-27
John Carter
No

Yes, I know this is weird, but it is standard compliant C and used in protothreads and Duff's device.

int bah(int state)
{
int i = 0;
int n = 7;
switch(state) {case 0:
i=0;
while(i<10) {
state = 10;
/*@fallthrough@*/ case 10:
n = i;
i++;
}
}

return i;
}

/opt/splint-3.1.2/bin/splint bug.c
Splint 3.1.2 --- 08 Jan 2010

bug.c: (in function bah)
bug.c:4:8: Variable n declared but not used
A variable is declared but never used. Use /*@unused@*/ in front of
declaration to suppress message. (Use -varuse to inhibit warning)

Finished checking --- 1 code warning

This is possibly related to https://sourceforge.net/tracker/?func=detail&atid=459911&aid=1960107&group_id=34302

Discussion

  • John Carter

    John Carter - 2011-06-27

    Example that triggers false positive.

     
  • Bill Pringlemeir

    What if state is 7? Or anything not 0 or 10? Maybe the original code was more complex. Also, the splint options and configuration file would be helpful.

     
  • John Carter

    John Carter - 2011-08-28

    No flags where used on the splint command line. ie. Default flags."splint bug.c"

    splint --help version
    Splint 3.1.1 --- 15 Dec 2010

    Maintainer: splint-bug@splint.org
    Compiled using gcc -g -O2 on Linux parore 2.6.35-23-generic-pae #41-Ubuntu SMP
    Wed Nov 24 10:35:46 UTC 2010 i686 GNU/Linux by root

    You can vary that code in the following ways...

    If you change the "while" to an "if".. still standard C that compiles with no warnings under gcc -c -O3 -Wall -W
    Splint returns...

    bug.c:14:5: Parse Error: Likely parse error. Conditional clauses are
    inconsistent.. (For help on parse errors, see splint -help parseerrors.)
    *** Cannot continue.

    If you move the "case 10:" before the "while", or after the "n = i" splint gives no warnings

    If you vary the case label or the value in "state = 10", splint still gives false positive.

     
  • John Carter

    John Carter - 2011-08-28

    Question for Bill, have you been able to reproduce the error? Or does it just "Work For You"? In which case you may be on a different version and I will pull the tip of the CVS version and try that.

    Thanks

     

Log in to post a comment.

MongoDB Logo MongoDB