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

            bug534.cpp

1     #include <stdio.h>
2
3     /* return the length of the nth line */
4     int line_len( char *filename, int n )
5         {
6         FILE *f;
7         char buf[200];
8         int j, i=0;
9         if( (f = fopen( filename, "r" )) )
10            {
11            for( j = 0; j < n; j++ ) fgets( buf, 200, f );
12            for( i = 0; buf[i]; i++ ) /* find end of buf */;
13            fclose(f);
14            }
15        return i;
16        }
17
18    int main()
19        {
20        printf( "%d\n", line_len( "test.txt", 3 ) );
21        return 0;
22        }

Will the programmer print the length of the 3rd line of file test.txt or can something go wrong?


bug534.cpp lint Output

--- Module:   bug534.cpp
                                     _
    if( (f = fopen( filename, "r" )) )
bug534.cpp(9) : Info 720: Boolean test of assignment
                                                     _
        for( j = 0; j < n; j++ ) fgets( buf, 200, f );
bug534.cpp(11) : Warning 534: Ignoring return value of function 'fgets(char *,
    int, struct _iobuf *)' (compare with line 300, file C:\program
    files\microsoft visual studio\vc98\include\stdio.h)
                          _
        for( i = 0; buf[i]; i++ ) /* find end of buf */;
bug534.cpp(12) : Info 771: Symbol 'buf' (line 7) conceivably not initialized


Reference Manual Explanation

 
534    Ignoring return value of Symbol (compare with Location)  -- A
       function that returns a value is called just for side effects as,
       for example, in a statement by itself or the left-hand side of a
       comma operator.  Try: (void) function(); to call a function and
       ignore its return value.  See also the fvr, fvo and fdr flags.


Previous Bug - Bug #1747 - March 2001

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright © 2003, Gimpel Software