facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.83k stars 2k forks source link

infer doesn't understand for(;;) loops in C #1713

Open mulle-nat opened 1 year ago

mulle-nat commented 1 year ago

infer run -- clang -c foo.c

Capturing in make/cc mode...
Found 1 source file to analyze in /tmp/infer-out
1/1 [################################################################################] 100% 51.704ms

foo.c:9: error: Uninitialized Value
  The value read from rval was never initialized.
   7.       rval = 1;
   8.    }
   9.    if( rval == 2)
             ^
  10.       return( 1);
  11.    return( 0);

Found 1 issue
                Issue Type(ISSUED_TYPE_ID): #
  Uninitialized Value(UNINITIALIZED_VALUE): 1

foo.c:

int  main( void)
{
   int   rval;

   for(;;)
   {
      rval = 1;
   }
   if( rval == 2)
      return( 1);
   return( 0);
}
mulle-nat commented 1 year ago

To make it more real life, put a break after rval = 1, which makes no difference.