I'm trying to fix some C++ code with address sanitizer. The code says:
unsigned result = *(uint32_t*)data;
And the sanitizer gives:
runtime error: load of misaligned address 0x6280033f410a for type 'uint32_t', which requires 4 byte alignment
How do I need to fix this?
You need to create an aligned object (such as a variable), and copy the content from the misaligned address:
This assumes that you intend to read
sizeof u32
bytes from that address and that those bytes are ordered in native endianness.Implicit conversion should be just fine: