Click on image to see enlargment

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

            bug722.cpp

1    #include <stdio.h>
2
3    #define N 10
4    int a[N];
5    void fill_upper( int from, int fill )
6        {
7        int i, j;
8        for( i = from; i < N; i++ )
9            a[i] = fill;
10       for( j = 0; j < from; j++ );
11           a[j] = 0;
12       }
13   int main()
14       {
15       fill_upper( 8, 22 );
16       printf( "a[] contains " );
17       for( int i = 0; i < N; i++ ) printf( "%d ", a[i] );
18       printf( "\n" );
19       return 0;
20       }

The programmer wrote the fill_upper() function to fill in the upper reaches of the array a[]. With an argument of 8 he expected to fill a[8] and a[9] with the value 22. When printing the array only a[9] appeared to be filled in. What's going wrong?


bug722.cpp lint Output

--- Module:   bug722.cpp
                              _
    for( j = 0; j < from; j++ );
bug722.cpp(10) : Info 722: Suspicious use of ;
        _
        a[j] = 0;
bug722.cpp(11) : Warning 539: Did not expect positive indentation from line 10

Reference Manual Explanation


722   Suspicious use of ;  -- A semi-colon was found immediately to
      the right of a right parenthesis in a construct of the form
      while(e); or for(e;e;e);  As such it may be overlooked or
      confused with the use of semi-colons to terminate statements.
      The message will be inhibited if the ';' is separated by at
      least one blank from the ')'. Better, place it on a separate line.

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

Previous Bug - Bug #1509 - August 2005

[ new ] 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 2006, Gimpel Software, All rights reserved.