From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeffrey A Law To: Falk Hueffner Cc: gcc@gcc.gnu.org Subject: Re: Array out of bounds warning Date: Mon, 31 Jul 2000 07:11:00 -0000 Message-id: <15088.965052644@upchuck> References: <87d7jv8i9p.fsf@student.uni-tuebingen.de> X-SW-Source: 2000-07/msg01008.html 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