From: Nathael Pajani Date: Sat, 16 Mar 2019 16:26:49 +0000 (+0100) Subject: Use memcpy as data may not be word aligned X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=db72ed31bfea37d27ec9a3465e8534b4f48b4748;p=soft%2Flpc122x%2Fcore Use memcpy as data may not be word aligned --- 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) {