From db72ed31bfea37d27ec9a3465e8534b4f48b4748 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sat, 16 Mar 2019 17:26:49 +0100 Subject: [PATCH] Use memcpy as data may not be word aligned --- lib/protocols/mqtt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protocols/mqtt.c b/lib/protocols/mqtt.c index d9e9ef3..d11a809 100644 --- a/lib/protocols/mqtt.c +++ b/lib/protocols/mqtt.c @@ -330,7 +330,7 @@ int mqtt_unpack_publish_packet(struct mqtt_publish_pkt* pkt, uint8_t* buf, uint3 return -EPROTO; } /* Decode topic string */ - tmp = *((uint16_t*)(buf + idx)); + memcpy(&tmp, (buf + idx), 2); topic_len = ntohs(tmp); pkt->topic.name = (char*)(buf + idx + 2); idx += topic_len + 2; @@ -338,9 +338,9 @@ int mqtt_unpack_publish_packet(struct mqtt_publish_pkt* pkt, uint8_t* buf, uint3 return -EPROTO; } /* Decode packet ID */ - tmp = *((uint16_t*)(buf + idx)); - pkt->packet_id = ntohs(tmp); idx += 2; + memcpy(&tmp, (buf + idx), 2); + pkt->packet_id = ntohs(tmp); /* Get application message */ pkt->message_size = size - idx; if (pkt->message_size != 0) { -- 2.43.0