4

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]) )
1

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

@user1952119: Fine, give me a little 15 hours to check your 3000 lines and I'll catch you later!
Best answer I can give you: Contact Rajdeep Patel, if that person is not you.
So if it not declared in that file I need to find where it is and make sure it set to lower or equal to 12?
Found it... #define TOTAL_INTERRUPT_SETS 14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.