Gimpel Software
  Order        Patches        Discussion Forum        Blog 
Contact      Site Map       
   Home
   Bug of the Month
   Products
   Order
   Support
   Company
   Links
   Interactive Demo

How many bugs can you find in this program?

How many can your compiler find?

  1 // The following example illustrates the use of the semantic option.
  2 //lint -sem( fill, 1p >= N )  fill’s argument points to an area that
  3 //                            must be at least N in length.
  4 //lint -sem( copy, @p == 1p ) copy’s return value points to an area
  5 //                            equal in size to that of its argument.
  6
  7 #include <stdlib.h>
  8 #include <string.h>
  9 void fill( char * );
 10 char *copy( char * );
 11
 12 #define N 100
 13
 14 void f()
 15     {
 16     char buffer[N];
 17     char *p;
 18     char *q;
 19
 20     p = (char *) malloc( N );
 21     p++;
 22     fill( buffer );
 23     fill( p );
 24     q = copy( p );
 25     strcpy( q, buffer );
 26     free( buffer );
 27     free( p );
 28     }

OK - What's Wrong?

 

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software LLC
Copyright © 2015, Gimpel Software LLC, All rights reserved.