Order        Lint 8.00 Patches        Discussion Forum   
Contact      Site Map       
   Home
   Bug of the Month
   Products
   Order
   Support
   Company
   Links
   Interactive Demo
  Search:
site web

  How many bugs can you find in this program?

    How many can your compiler find?

  1  #include <string.h>
  2  #include <stdlib.h>
  3  #include <stdio.h>
  4
  5  #define Extract(ch) (ch) & 0xFf
  6  #define Value(ch) ((ch) > '0' && \
  7          (ch) <= '9' ? (ch) - '0' : 0)
  8  #define Abs(x) ( (x) < 0 ? -x : (x) )
  9
 10  void readline( char *fn )
 11      {
 12      FILE *f;
 13      char buf[100];
 14
 15      if( !fn ) printf( "bad file\n" );
 16      f = fopen( fn, "r" );
 17      (void) fgets( buf, 101, f );
 18      fclose( f );
 19      }
 20
 21  int compute( char *s )
 22      {
 23      int sum = 0;
 24      while( *s )
 25          sum = sum + Value(Extract(*s++));
 26      return Abs( sum - 100 );
 27      }
 28
 29  class String
 30      {
 31    private:
 32      char *a;
 33      unsigned len;
 34    public:
 35      String( char *s = 0 )
 36          {
 37          if( s )
 38              {
 39              len = strlen(s);
 40              a = new char[len];
 41              strcpy( a, s );
 42              }
 43          }
 44      ~String() { len = 0; }
 45      String( const String & );
 46      String & operator=( const String &s )
 47          {
 48          len = s.len;
 49          a = new char[len];
 50          memcpy( a, s.a, len );
 51          return s;
 52          }
 53     };

OK - What's Wrong?

 

Home | Contact | Order

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