From d07f759ca35ef8095c19c5dc8ae4354ce5367ce5 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 1 Sep 2018 12:00:38 +0200 Subject: [PATCH] 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. --- libgnucash/engine/gnc-timezone.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libgnucash/engine/gnc-timezone.cpp b/libgnucash/engine/gnc-timezone.cpp index 876df2aac5..01325b457a 100644 --- a/libgnucash/engine/gnc-timezone.cpp +++ b/libgnucash/engine/gnc-timezone.cpp @@ -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(&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],