--- libaitmqtt/src/pub.c 2012/06/21 13:47:30 1.2.2.1 +++ libaitmqtt/src/pub.c 2012/06/28 11:06:17 1.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pub.c,v 1.2.2.1 2012/06/21 13:47:30 misho Exp $ +* $Id: pub.c,v 1.3 2012/06/28 11:06:17 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -128,7 +128,7 @@ mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha static int _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, u_short msgID) { - int siz = 0; + int siz = sizeof(struct mqtthdr); struct mqtthdr *hdr; mqtt_len_t *v; @@ -137,12 +137,8 @@ _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, if (mqtt_msgRealloc(buf, sizeof(struct mqtthdr) + sizeof(mqtt_len_t)) == -1) return -1; - else { - hdr = (struct mqtthdr *) (buf->msg_base + siz); - siz += sizeof(struct mqtthdr); - v = (mqtt_len_t*) (buf->msg_base + siz); - siz += sizeof(mqtt_len_t); - } + else + hdr = (struct mqtthdr *) buf->msg_base; /* fixed header */ MQTTHDR_MSGINIT(hdr); @@ -150,7 +146,9 @@ _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd, *hdr->mqtt_len = sizeof(mqtt_len_t); /* MessageID */ + v = (mqtt_len_t*) (buf->msg_base + siz); v->val = htons(msgID); + siz += sizeof(mqtt_len_t); return siz; }