How to fix 'array subscript is above array bounds' ?

David Aldrich David.Aldrich@EMEA.NEC.COM
Tue Apr 3 16:06:00 GMT 2012


Thanks, sorry to have missed that.

David

> -----Original Message-----
> From: Dan Hitt [mailto:dan.hitt@gmail.com]
> Sent: 03 April 2012 17:04
> To: David Aldrich
> Cc: gcc-help@gcc.gnu.org
> Subject: Re: How to fix 'array subscript is above array bounds' ?
> 
> On Tue, Apr 3, 2012 at 8:59 AM, David Aldrich
> <David.Aldrich@emea.nec.com> wrote:
> > Hi
> >
> > We normally use gcc 4.1.2 to compile our C++ code, but I am now
> experimenting with gcc 4.4.6.
> >
> > I am getting a compiler warning with 4.4.6, that I did not see with 4.1.2, and
> I don't understand how to fix it.
> >
> > Here's the code:
> >
> > myFunc(int& a_mcsIndex)
> > {
> >    const unsigned SPS_MCS_TABLE_SIZE = 4;
> >    const int SPS_MCS_TABLE_MCS[SPS_MCS_TABLE_SIZE] = { 19, 12, 8, 6};
> >
> >    for ( unsigned ind=0; ind<SPS_MCS_TABLE_SIZE; ind++ )
> >   {
> >       a_mcsIndex = SPS_MCS_TABLE_MCS[ind-1];                <=== warning
> 
> Could (ind-1) be some huge number if ind is 0?
> 
> dan
> 
> >
> > Warning: array subscript is above array bounds
> >
> > How can I fix this warning please?
> >
> > Best regards
> >
> > David
> >
> 
> 
>  Click
> https://www.mailcontrol.com/sr/!W6ykfoBU8bTndxI!oX7UtF+E!9qmZJeryEI
> 0U7VA4CvzwqrBtPy9TxAff79E4G5T6F5wXAHOrCgvJyt6ermNw==  to report
> this email as spam.



More information about the Gcc-help mailing list