Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug587.cpp

1    #include <stdlib.h>
2    // check_serial returns true if the
3    //   serial number is OK.
4    bool check_serial( unsigned serial )
5        {
6        if( (serial & 0x2E537B4) == 0x2C42540 )
7            return true;
8        else return false;
9        }
10   // main() returns 0 if the serial number
11   //   is OK and non-zero otherwise.
12   int main( int argc, char* argv[] )
13       {
14       unsigned serial_no;
15       if( argc <= 1 ) return 2;
16       serial_no = (unsigned) atoi( argv[1] );
17       if( check_serial( serial_no ) ) return 0;
18       else return 1;
19       }

Much to the chagrin of European bankers, Abraham Lincoln issued greenbacks to finance the Civil War. This program represents an early effort to detect counterfeit greenbacks. But something's going wrong. Can you spot it?


bug587.cpp lint Output

--- Module:   bug587.cpp (C++)
                                          _
    if( (serial & 0x2E537B4) == 0x2C42540 )
bug587.cpp(6) : Warning 587: Predicate '==' can be pre-determined and always
    evaluates to False
    _
    }
bug587.cpp(19) : Info 818: Pointer parameter 'argv' (line 12) could be declared
    as pointing to const

Reference Manual Explanation


587    Predicate 'String' can be pre-determined and always evaluates to String  --
       The predicate, identified by the first String, (one of greater than, greater than
       or equal, less than, less than or equal, equal, or not equal), cannot possibly be
       other than what is indicated by the second String parameter.  For example:

                 unsigned u; ...
                 if( (u & 0x10) == 0x11 ) ...

       would be greeted with the message that '==' always evaluates to 'False'.


If you have comments or questions about this bug, please post them to our   Discussion Forum


Previous Bug - Bug #1416 - January 2009

Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

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