Click on image to see enlargment

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


1    #define N_CUST 10000    // no. of customers
2    #define LIMIT 20        // limit per customer
3    int liters[N_CUST];     // liters consumed
4    int *upper_bound(int);
6    int main()          // Oktoberfest Limit Checker
7        {
8        for( int *p = liters; p < upper_bound(N_CUST+1); p++ )
9            {
10           *p = 0;     // initialize liters to 0
11           }
12       return 0;
13       }
15   int *upper_bound( int bound )
16       {
17       return liters+bound;
18       }

This is the start of a larger program to monitor beer consumption at a large gathering, but the program already has a serious problem. Can you spot it?

bug416.cpp lint Output

--- Module:   bug416.cpp

During Specific Walk:
  File bug416.cpp line 8: upper_bound(10001)
bug416.cpp  17  Warning 416: Likely creation of out-of-bounds pointer (2 beyond
    end of data) by operator 'ptr+int' [Reference: file bug416.cpp: lines 8, 17]

    --- Wrap-up for Module: bug416.cpp

Info 750: local macro 'LIMIT' (line 2, file bug416.cpp) not referenced

Reference Manual Explanation

416   creation of out-of-bounds pointer ('Integer' beyond end of data) by
      operator 'String'  -- An out-of-bounds pointer was created. See
      message 415 for a description of the parameters Integer and String.
      For example:

                int a[10];


                f( a + 11 );

      Here, an illicit pointer value is created and is flagged as such by
      PC-lint/FlexeLint.  Note that the pointer a+10 is not considered by
      PC-lint/FlexeLint to be the creation of an out-of-bounds pointer. This
      is because ANSI C explicitly allows pointing just beyond an array. Access
      through a+10, however, as in *(a+10) or the more familiar a[10], would
      be considered erroneous but in that case message 415 would be issued.

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

Previous Bug - Bug #722 - September 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.