Pointed Array Access
by Remy Porter
in CodeSOD
on 2018-10-01
I've spent the past week doing a lot of embedded programming, and for me, this has mostly been handling having full-duplex communication between twenty devices on the same serial bus. It also means getting raw bytes and doing the memcpy(&myMessageStructVariable, buffer, sizeof(MessageStruct))
. Yes, that's not the best way, and certainly isn't how I'd build it if I didn't have full control over both ends of the network.
Of course, even with that, serial networks can have some noise and errors. That means sometimes I get a packet that isn't the right size, and memcpy
will happily read past the end of the buffer, because my const uint8_t * buffer
pointer is just a pointer, after all. It's on me to access memory safely. Errors result when I'm incautious.