From dbde7839216dd997dd8b5403e275923387f4affc Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Thu, 23 Mar 2017 14:13:28 +0300 Subject: Replace variable assignment with memcpy for parse When message arrived, its packed, so depending on compiler it may lead to unaligned memory access. Change-Id: Ic9976904ad70a9610bb8b5f00886ec1474a7bee1 Signed-off-by: Alexander Aksenov --- daemon/da_protocol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index d811c03..bc11137 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -301,7 +301,9 @@ int parse_int32(struct msg_buf_t *msg, uint32_t *val) parse_deb("size = %d\n", get_avail_msg_size(msg)); if (get_avail_msg_size(msg) < sizeof(*val)) return 0; - *val = *(uint32_t *)msg->cur_pos; + /* Use memcpy, because when parsing incoming message memory is unaligned + * in general */ + memcpy(val, msg->cur_pos, sizeof(*val)); msg->cur_pos += sizeof(uint32_t); @@ -316,7 +318,9 @@ int parse_int64(struct msg_buf_t *msg, uint64_t *val) if (get_avail_msg_size(msg) < sizeof(*val)) return 0; - *val = *(uint64_t *)msg->cur_pos; + /* Use memcpy, because when parsing incoming message memory is unaligned + * in general */ + memcpy(val, msg->cur_pos, sizeof(*val)); parse_deb("<%llu><0x%016llX>\n", *val, *val); msg->cur_pos += sizeof(uint64_t); -- cgit v1.2.3