Click on image to see enlargment

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

            bug650.cpp

1    #include <stdio.h>
2    typedef const char *cString;
3    cString teams[] =
4        {
5        "Giants", "Cowboys", "Eagles", "Redskins",
6        "Lions", "Packers", "Bears", "Vikings",
7        "Bills", "Dolphins", "Patriots", "Jets",
8        /* ... */
9        };
10   #define Nlist (sizeof(teams) / sizeof(teams[0]))
11   int main()
12       {
13       size_t i;
14
15       for( i = 0; i < Nlist; i++ )
16           {
17           printf( "%s  ", teams[i] );
18           if( i % 4 == 4 ) printf( "\n" );
19           }
20       printf( "\n" );
21       return 0;
22       }

A football analyst wanted to print out the names of football teams, blank-separated, four to a line. What could go wrong with such a simple program?


bug650.cpp lint Output

--- Module:   bug650.cpp (C++)
                       _
        if( i % 4 == 4 ) printf( "\n" );
bug650.cpp(18) : Warning 650: Constant '4' out of range for operator '=='

--- Global Wrap-up

Info 843: Variable 'teams' (line 3, file bug650.cpp) could be declared as const

Reference Manual Explanation


650    Constant out of range for operator String  -- In a comparison
       operator or equality test (or implied equality test as for a case
       statement), a constant operand is not in the range specified by
       the other operand.  For example, if 300 is compared against a
       char variable, this warning will be issued.  Moreover, if char is
       signed (and 8 bits) you will get this message if you compare
       against an integer greater than 127.  The problem can be fixed
       with a cast.  For example:

                 if( ch == 0xFF ) ...
                 if( (unsigned char) ch == 0xFF ) ...

       If char is signed (+fcu has not been set) the first receives a
       warning and can never succeed.  The second suppresses the warning
       and corrects the bug.

       PC-lint/FlexeLint will take into account the limited precision of
       some operands such as bit-fields and enumerated types.  Also,
       PC-lint/FlexeLint will take advantage of some computations that
       limit the precision of an operand.  For example,

                 if( (n & 0xFF) >> 4 == 16 ) ...

       will receive this warning because the left-hand side is limited
       to 4 bits of precision.


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


Previous Bug - Bug #444 - September 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.