Click on image to see enlargment

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

            bug444.cpp

1    #include <stdio.h>
2    enum party { dem, rep, ind };
3    struct ABC
4        { const char *name; party affil; } A[] =
5    {
6        { "Mary Smith", rep },
7        { "Jack Spratt", dem },
8        { "Arch Emides", ind }
9        /* ... */
10   };
11   int main()
12       {
13       struct ABC *p;
14       for( p = A; p; p++ )
15           {
16           if( p->affil == ind )
17               printf( "%s (ind)\n", p->name );
18           }
19       return 0;
20       }

Armed with a list of first grade students and their parents' political affiliation, the principal wanted to have a list of all the potential trouble makers. But in addition to something wrong with the program, there is something wrong with this program. Can you spot it?


bug444.cpp lint Output

--- Module:   bug444.cpp (C++)
                       _
    for( p = A; p; p++ )
bug444.cpp(14) : Warning 444: for clause irregularity: pointer 'p' incremented
    in 3rd expression is tested for NULL in 2nd expression

Reference Manual Explanation


444    for clause irregularity: pointer 'Symbol' incremented in 3rd
       expression is tested for NULL in 2nd expression  -- The following
       kind of situation has been detected:

                 for( ... ; p == NULL; p++ )
                     ...

       A loop variable being incremented or decremented would not
       normally be checked to see if it is NULL.  This is more likely a
       programmer error.


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


Previous Bug - Bug #777 - August 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.