From 39d0c7af506ea7c5703192ec7ffa07bdd6853b26 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sat, 16 Mar 2019 17:30:08 +0100 Subject: [PATCH] Use return value in order to return the topic string size as the topic string is not null terminated. --- lib/protocols/mqtt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protocols/mqtt.c b/lib/protocols/mqtt.c index d0a62d4..6a6cef7 100644 --- a/lib/protocols/mqtt.c +++ b/lib/protocols/mqtt.c @@ -309,6 +309,7 @@ int mqtt_pack_publish_packet(const struct mqtt_publish_pkt* pkt, uint8_t* buf, u * The function also checks the validity of the packet. * All returned pointers within the struct will point to parts of the provided buffer, so the buffer * must not be discarded after the call. + * if the return value is positive, it is the topic string length. */ int mqtt_unpack_publish_packet(struct mqtt_publish_pkt* pkt, uint8_t* buf, uint32_t size) { @@ -359,7 +360,7 @@ int mqtt_unpack_publish_packet(struct mqtt_publish_pkt* pkt, uint8_t* buf, uint3 if (pkt->message_size != 0) { pkt->application_message = (buf + idx); } - return 0; + return topic_len; } /***************************************************************************** */ -- 2.43.0