Click on image to see enlargment

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

            bug795.cpp

1     #include <stdio.h>
2     #define N 6
3     double wind_velocity[N] = { 0.0, 14.1, 5.6, 6.0, 23.3, 15.0 } ;
4     double ave_wind( int n )
5         {
6         int j = 0;
7         double sum = 0.0;
8         for( int i = 1; i <= n; i++ )
9             {
10            sum += wind_velocity[i];
11            j = i;
12            }
13        return wind_velocity[j]/j;
14        }
15    int main()
16        {
17        for( int i = 0; i < N; i++ )
18            printf( "%d %g\n", i , ave_wind(i) );
19        return 0;
20        }

In determining the average wind velocity of the first 5 days of March the programmer made one of those errors that caused a bit of embarrassment during a customer demonstration. What went wrong?


bug795.cpp lint Output

--- Module:   bug795.cpp
                             _
    return wind_velocity[j]/j;
bug795.cpp(13) : Info 795: Conceivable division by 0 [Reference: file bug795.cpp: line 6]
    _
    }
bug795.cpp(14) : Warning 550: Symbol 'sum' (line 7) not accessed

Reference Manual Explanation

 
795   Conceivable division by 0  -- In a division or modulus operation the division is
      deduced to be conceivably 0. See Section 9.2 Value Tracking for the meaning of
      "conceivable".

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

Previous Bug - Bug #427 - February 2004

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