MCP2517FD API: access to out-of-bounds array element?

0

I stumbled upon the following line of code corresponding to the MCP2517FD API developed by Microchip, used as a controller to a CAN-FD network:

ciFifoCon.word = canControlResetValues[cREGADDR_CiFIFOCON / 4];
#This line is used several times on the code.

Where ciFifoCon is a struct of 32 bits with a word field and several bits, and canControlResetValues is the following array:

static uint32_t canControlResetValues[] = {
    /* Address 0x000 to 0x00C */
    0x04980760, 0x003E0F0F, 0x000E0303, 0x00021000,
    /* Address 0x010 to 0x01C */
    0x00000000, 0x00000000, 0x40400040, 0x00000000,
    /* Address 0x020 to 0x02C */
    0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* Address 0x030 to 0x03C */
    0x00000000, 0x00200000, 0x00000000, 0x00000000,
    /* Address 0x040 to 0x04C */
    0x00000400, 0x00000000, 0x00000000, 0x00000000
};

And _cREGADDR_CiFIFOCON_ is defined ad 0x50:

#define cREGADDR_CiFIFOCON  0x050

The problem: cREGADDR_CiFIFOCON/4=20, which should access an element of the array that is out of bounds! The code compiles without problems, but this should have an undefined behaviour. I'm trying to understand if this is an error (and if it is, what were the developers really trying to do), or it is done intentionally with some purpose I don't understand.

I appeciate your help and thanks.

c
arrays
undefined-behavior
asked on Stack Overflow May 20, 2019 by jcf

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0