Hello,
A colleague of mine, while processing some binary data, transfered a RAM memory address to a function. That address was not even (ARM7 architecture) so the LDR instruction behaved exactly as the assembly manual specifies it should in case of a misaligned address - round in the address + some more shift magic, which created a memory access off by 1 byte. My question is: Is there a way to deal with this runtime error in advance?
My question is: Is there a way to deal with this runtime error in advance?
Sure there is. You can use __packed pointers (feature of Realview) to access unaligned data. You can detect unaligned pointers using some arithmetics:
if ((uintptr_t)ptr & 3 != 0) { /* Error: bad pointer alignment */ }