Warning: file.c(212): warning: C4487E: read from variable 'config' with offset out of bounds
I'm getting this warning with the following code:
uint16_t config = 100; uint8_t configMsg[2][4]; memcpy(configMsg[0], &config, sizeof(configMsg[0]));
But I don't understand why. Anyone have any insights? It compiles w/o warning if I sub in memcpy(configMsg[0], &config, 3);
But if I sub in memcpy(configMsg[0], &config, 4); it generates the warning again.
config is 2 bytes wide, why are you even specifying 3, or 4?
those are just examples. i'm trying to understand why this warning occurs.
i don't think its a good practice to do a memcpy with the size set to the sizeof (source) as you can get buffer overflows, so I try to do sizeof(destination) as the length.
How about doing the MIN() of both. The warning comes from doing something so patently wrong the compiler can see it at build time.
memcpy() is one of the thing the compiler turns into an intrinsic for small copies.
View all questions in Keil forum