Click on image to see enlargment

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

            bug443.cpp

1    #include <stdio.h>
2    #include <string.h>
3    #define N 10000
4    char corpus[N] = "... to be or not to be ...";
5    void Shakespeare( const char * text )
6        {
7        int span;   // distance between related characters
8        int len = (int) strlen(text);
9        for( span = 1; span < 100; span++ )
10           for( int i = 0; i < N - 100 * len; i++ )
11               {
12               int j;
13               for( j = 0; j < len; i++ )
14                   if( text[j] != corpus[i + j * span] )
15                       break;
16               if( j == len ) printf( "Discovered %s\n", text );
17               }
18       }
19   int main() { Shakespeare( "Oxford" ); return 0; }

Willoughby did write this program on the chance that the great bard left humanity a clue as to his very identity. Here a portion of the Shakespeare canon is searched for the word "Oxford" each of whose letters would be equi-separated by a span of the same length. But alas this ill-fated code functions not and this web is for thee to untangle.


bug443.cpp lint Output

--- Module:   bug443.cpp (C++)
                                     _
            for( j = 0; j < len; i++ )
bug443.cpp(13) : Warning 440: for clause irregularity: variable 'j' tested in 2nd expression
    does not match 'i' modified in 3rd 
bug443.cpp(13) : Warning 443: for clause irregularity: variable 'j' initialized in 1st
    expression does not match 'i' modified in 3rd 
bug443.cpp(13) : Warning 445: Reuse of for loop variable 'i' at 'line 10' could cause chaos
    _
    }
bug443.cpp(18) : Info 850: for loop index variable 'i' whose type category is 'integral' is
    modified in body of the for loop that began at 'line 10'

Reference Manual Explanation


443    for clause irregularity: variable 'Symbol' initialized in 1st expression does not match
       'Symbol' modified in 3rd  -- A for clause has a suspicious structure.  The loop variable,
       as determined by an examination of the 3rd for clause expression, does not match the
       variable that is initialized in the 1st expression.  For example:

                 for( ii = 0; i < 10; i++ )
                     ...

       would draw this complaint since the 'ii' of the 1st expression does not match the 'i' of
       the third expression.




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


Previous Bug - Bug #1570 - October 2011

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 2011, Gimpel Software, All rights reserved.