This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Array out of bounds warning



  In message <87d7jv8i9p.fsf@student.uni-tuebingen.de>you write:
  > Hi,
  > 
  > the Compaq C compiler has a warning for an array out of bounds access
  > with constant index (and known array size, of course), like this:
  > 
  > int a[10];
  > a[10] = 17;
  > 
  > I've already discovered two nasty bugs with this warning, so I
  > wondered whether it might be worth adding it to gcc. It can be
  > erroneously triggered with code that allocates extra space after the
  > array, for example by putting it into a union. These arrays usually
  > have a size of 1, so the Compaq C compiler has a special warning for
  > that which can be toggled seperately. I'd rather never warn in this
  > condition, so I suggest something like this:
It might make more sense to put this in expr.c so that other languages
can get similar checks.  You might also check that the low bound is within
range.

The next question in my mind is how often do we get false hits on the
warning.

But I generally like the idea of issuing a warning if the code is obviously
wrong.  

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]