Use alignment-safe buffer handling

Casting a char* to a struct containing a uint32_t is not universally safe
due to alignment constraints on reads on some platforms. Copy our possibly
unaligned source data into an aligned area of memory to avoid SIGBUS on
armhf.
Reported by vorlonofportland in PR#403. This commit the John's optimized
version of Vorlon's proposed fix.
pull/404/head
Geert Janssens 8 years ago
parent 4c87dd05ec
commit d07f759ca3

@ -471,7 +471,9 @@ namespace IANAParser
for(uint32_t index = 0; index < type_count; ++index)
{
fb_index = start_index + index * tzinfo_size;
TTInfo info = *reinterpret_cast<TTInfo*>(&fileblock[fb_index]);
/* Use memcpy instead of static_cast to avoid memory alignment issues with chars */
TTInfo info{};
memcpy(&info, &fileblock[fb_index], ttinfo_size);
endian_swap(&info.gmtoff);
tzinfo.push_back(
{info, &fileblock[abbrev + info.abbrind],

Loading…
Cancel
Save