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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Aldrich <David.Aldrich@xxxxxxxxxxxx> writes:

> Actually I have a harder example of this warning to fix.  What should one do in this situation please?
>
> unsigned rsCodeTable( unsigned a_rsGroup, unsigned a_sc )
> {
>         static const unsigned PUCCHIP_RSCodeTable[30][12] = {
>         {2, 1, 0, 3, 0, 0, 1, 1, 0, 1, 3, 0},
>         {1, 1, 0, 0, 0, 2, 1, 3, 3, 1, 3, 0},
>         {1, 1, 3, 3, 3, 2, 3, 3, 1, 3, 1, 2},
>         {2, 1, 1, 1, 1, 2, 3, 3, 1, 3, 0, 2},
>         {2, 0, 1, 2, 1, 2, 3, 2, 1, 2, 1, 0},
>         {1, 3, 0, 2, 2, 1, 1, 2, 2, 0, 3, 1},
>         {2, 0, 3, 3, 3, 0, 1, 2, 0, 0, 3, 1},
>         {3, 2, 2, 2, 1, 3, 0, 2, 1, 3, 0, 1},
>         {1, 3, 0, 1, 2, 2, 2, 1, 1, 0, 2, 1},
>         {1, 3, 2, 0, 0, 2, 3, 1, 1, 1, 1, 1},
>         {2, 0, 2, 1, 1, 3, 3, 2, 3, 3, 0, 2},
>         {0, 1, 2, 2, 0, 0, 3, 1, 0, 1, 0, 0},
>         {1, 3, 1, 1, 3, 1, 1, 1, 3, 3, 3, 1},
>         {0, 0, 3, 0, 3, 1, 1, 0, 2, 3, 0, 0},
>         {3, 1, 2, 3, 2, 0, 1, 0, 0, 0, 2, 1},
>         {0, 2, 1, 3, 2, 2, 1, 1, 0, 1, 2, 3},
>         {1, 0, 1, 2, 1, 0, 0, 0, 2, 2, 0, 2},
>         {3, 1, 1, 0, 3, 0, 3, 3, 0, 1, 0, 2},
>         {3, 0, 1, 1, 3, 1, 3, 3, 2, 2, 1, 3},
>         {2, 0, 1, 0, 1, 2, 2, 0, 3, 2, 3, 2},
>         {2, 3, 1, 1, 1, 1, 0, 1, 2, 1, 3, 2},
>         {2, 0, 2, 1, 3, 3, 3, 3, 3, 1, 2, 3},
>         {1, 1, 3, 3, 3, 3, 2, 0, 3, 1, 3, 0},
>         {1, 1, 2, 3, 2, 3, 1, 2, 1, 0, 2, 1},
>         {1, 1, 0, 1, 0, 0, 2, 1, 2, 3, 3, 1},
>         {1, 3, 0, 0, 1, 0, 0, 1, 3, 2, 2, 0},
>         {1, 0, 3, 3, 0, 3, 1, 2, 2, 0, 2, 3},
>         {3, 2, 3, 2, 3, 0, 1, 2, 1, 0, 3, 3},
>         {2, 0, 3, 0, 2, 0, 0, 3, 0, 0, 2, 2},
>         {0, 3, 3, 2, 2, 3, 2, 0, 3, 0, 1, 2} };
>     if ( a_rsGroup >= 30 ) fatal("PUCCHIP::rsCodeTable() : Illegal RS group number");
>     if ( a_sc      >= 12 ) fatal("PUCCHIP::rsCodeTable() : Illegal subcarrier number");
>
>     return PUCCHIP_RSCodeTable[a_rsGroup][a_sc];    <<== WARNING  'array subscript is above array bounds'
> }

Mark the function fatal with __attribute__ ((noreturn)).  Or change this
code to explicitly return.

Either way, GCC appears to have found some code which is invoking this
function without an out of range subscript.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux