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

            bug415.cpp

1    int array[10];
2
3    void sort_array( )
4        {
5        for( int i = 0; i < array[10]; i++ )
6            {
7            /* loop invariant:  array[0:i-1] are already sorted */
8            for( int j = i; j > 0; j-- )
9                {
10               if( array[j] < array[j-1] ) /* interchange */
11                   {
12                   int t = array[j];
13                   array[j] = array[j-1];  array[j-1] = t;
14                   }
15               }
16           }
17       }

This is a quick and dirty function (with the emphasis on dirty) to sort the global array[], but it keeps crashing. What is the programmer doing wrong?


bug415.cpp lint Output

--- Module:   bug415.cpp
                                 _
    for( int i = 0; i < array[10]; i++ )
bug415.cpp(5) : Warning 415: access of out-of-bounds pointer (1
    beyond end of data) by operator '['
bug415.cpp(5) : Warning 415: access of out-of-bounds pointer (1
    beyond end of data) by operator '['
    _
    }
bug415.cpp(17) : Warning 415: access of out-of-bounds pointer (1
    beyond end of data) by operator '['


Reference Manual Explanation

 
415    access of out-of-bounds pointer ('Integer' beyond end of data) by
       operator 'String'  -- An out-of-bounds pointer was accessed.
       String designates the operator.  The parameter 'Integer' gives
       some idea how far out of bounds the pointer may be.  It is
       measured in units given by the size of the pointed to object.
       The value is relative to the last item of good data and therefore
       should always be greater than zero.  For example:

             int a[10];
             a[10] = 0;

       results in an overflow message containing the phrase '1 beyond
       end of data'.


Previous Bug - Bug #1733 - September 2000

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

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