Click on image to see enlargment

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

            bug627.cpp

1    #include <stdio.h>
2
3    const char *wind[4] =
4        { "N 12 MPH", "NW 14 MPH", "N 22 MPH", NULL };
5
6    float average( const char *a[] )
7        {
8        float sum=0, vel=0;
9        int i;
10       char direction[10];
11       for( i = 0; a[i]; i++ ) {
12           sscanf( a[i], "%s %d", direction, &vel );
13           sum += vel;
14       }
15       return sum / i;
16       }
17
18   int main()
19       {
20       printf( "Average wind velocity is %g.\n", average(wind) );
21       return 0;
22       }

In computing the average wind velocity for a cold windy March day, the result, instead of being above 10 was below 1. What's the problem?


bug627.cpp lint Output

--- Module:   bug627.cpp (C++)
                                                _
        sscanf( a[i], "%s %d", direction, &vel );
bug627.cpp(12) : Warning 627: (arg. no. 4) indirect object inconsistent with format
                  _
    return sum / i;
bug627.cpp(15) : Info 795: Conceivable division by 0 [Reference: file
    bug627.cpp: line 11]
    _
    }
bug627.cpp(16) : Info 818: Pointer parameter 'a' (line 6) could be declared as
    pointing to const

Reference Manual Explanation


627    (arg. no. Integer) indirect object inconsistent with format   -- The type of an argument
       to scanf (or fscanf or sscanf) was inappropriate to the format.  However, the argument
       was a pointer and it pointed to a quantity of the expected size.

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

Previous Bug - Bug #1511 - February 2006

[ 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.