Click on image to see enlargment

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

            bug428.cpp

1    #include <stdio.h>
2    #define LENGTH 10
3    char a[LENGTH] = "567891234";
4    int ith_character( int );
5
6    int main()
7        {
8        int len = sizeof(a[LENGTH]);
9        printf(
10           "It's time to celebrate"
11           " the %cth of July\n",
12           ith_character( len-2 ) );
13       return 0;
14       }
15
16   int ith_character( int n )
17       {
18       return a[n];
19       }

In preparing a celebratory banner to honor his nation's birth the programmer noticed that a key character was missing from the expected output string. What went wrong?


bug428.cpp lint Output

--- Module:   bug428.cpp

During Specific Walk:
  File bug428.cpp line 12: ith_character(-1)
bug428.cpp(18) : Warning 428: negative subscript (-1) in operator '['
    [Reference: file bug428.cpp: lines 8, 12, 18]

Reference Manual Explanation


428    negative subscript (Integer) in operator 'String'  -- A negative
       integer was added to an array or to a pointer to an allocated
       area (allocated by malloc, operator new, etc.) This message is
       not given for pointers whose origin is unknown since a negative
       subscript is, in general, legal.

       The addition could have occurred as part of a subscript operation
       or as part of a pointer arithmetic operation.  The operator is
       denoted by String.  The value of the integer is given by Integer.

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

Previous Bug - Bug #424 - June 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.