3 ms·
This is a neat trick, but it will segfault in architectures where alignment is enforced (like MIPS, ARM, etc) if the input buffer is not suitably aligned. One r
by pbsd 13y ago
This is a neat trick, but it will segfault in architectures where alignment is enforced (like MIPS, ARM, etc) if the input buffer is not suitably aligned. One relatively cheap way to sidestep this is to memcpy into a stack-allocated struct:
Data data;
memcpy(&data, raw_buffer, sizeof data);
switch(data.data_type)
// ...
- signa11 13y agowell, there are 2 other options available: one is to use "--pointer_alignment=1" so that all accesses via the pointer are treated as unaligned OR use "--no_unaligned_access" flag to tell the compiler to not knowingly generate unaligned access