I looked around and didn't find anything that could help me.... I am building a kernel and am getting a few, array subscript is above array bounds, warnings which FAILS the build. I am using Linaro toolchain and set to -O3 so any warning will FAIL the build... Thanks for all the help
drivers/media/video/msm/rawchip/Yushan_API.c: In function 'Yushan_Check_Pad_For_IntrID':
drivers/media/video/msm/rawchip/Yushan_API.c:1751:85: warning: array subscript is above array bounds [-Warray-bounds]
error, forbidden warning: Yushan_API.c:1751
Here the method in which it fails...
bool_t Yushan_Check_Pad_For_IntrID(uint8_t bInterruptId)
{
uint8_t bFirstIndexForSet[] = {1, 5, 11, 17, 23, 27, 58, 62, 69, 77, 79, 82, 83};
uint8_t bIntrSetID = 0;
uint16_t uwIntrSetsDivertedToPad1 = 0;
VERBOSELOG("[CAM] %s: Start\n", __func__);
/* Read the list of the interrupt sets diverted to Pad1 */
SPI_Read(YUSHAN_IOR_NVM_SEND_ITR_PAD1 , 2, (uint8_t *)&uwIntrSetsDivertedToPad1);
/* Trace through InterruptSets */
while(bIntrSetID < TOTAL_INTERRUPT_SETS)
{
if( (bInterruptId>=bFirstIndexForSet[bIntrSetID])&&(bInterruptId<bFirstIndexForSet[bIntrSetID+1]) )
{
if((uwIntrSetsDivertedToPad1>>bIntrSetID)&0x01) {
VERBOSELOG("[CAM] %s: End\n", __func__);
return INTERRUPT_PAD_1;
} else {
VERBOSELOG("[CAM] %s: End\n", __func__);
return INTERRUPT_PAD_0;
}
} else
bIntrSetID++;
}
/* Just to remove warning */
VERBOSELOG("[CAM] %s: End\n", __func__);
return INTERRUPT_PAD_0;
}
It errors on line:
if( (bInterruptId>=bFirstIndexForSet[bIntrSetID])&&(bInterruptId < bFirstIndexForSet[bIntrSetID+1]) )
The index is exceeding the array's size at this call:
bFirstIndexForSet[bIntrSetID+1]
bFirstIndexForSet
has 13 elements, which requires indexes from 0 to 12.
You are looping for every indexes lower than TOTAL_INTERRUPT_SETS
, which should exceed 12.
(Since 11+1 would be the maximum index your array can use.)
Answer: Verify that TOTAL_INTERRUPT_SETS
is lower or equal to 12.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With