Skip to content

Commit

Permalink
Use alignment-safe buffer handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gjanssens committed Sep 1, 2018
1 parent 4c87dd0 commit d07f759
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libgnucash/engine/gnc-timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit d07f759

Please sign in to comment.