--- libaitmqtt/src/pub.c 2012/06/20 08:15:13 1.1.1.1.2.7 +++ libaitmqtt/src/pub.c 2012/06/21 13:47:30 1.2.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pub.c,v 1.1.1.1.2.7 2012/06/20 08:15:13 misho Exp $ +* $Id: pub.c,v 1.2.2.1 2012/06/21 13:47:30 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -64,7 +64,7 @@ mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha u_char Dup, u_char QOS, u_char Retain, const void *pData, int datlen) { int len, siz; - u_int n; + u_int n, *l; struct mqtthdr *hdr; mqtthdr_var_t *topic; mqtt_len_t *mid; @@ -72,8 +72,6 @@ mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha if (!buf || !csTopic) return -1; - else - data = buf->msg_base; if (QOS > MQTT_QOS_EXACTLY) { mqtt_SetErr(EINVAL, "Invalid QoS parameter"); return -1; @@ -95,8 +93,10 @@ mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha if (mqtt_msgRealloc(buf, siz + len) == -1) return -1; - else + else { + data = buf->msg_base; hdr = (struct mqtthdr *) data; + } /* fixed header */ MQTTHDR_MSGINIT(hdr); @@ -104,7 +104,8 @@ mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha hdr->mqtt_msg.qos = QOS; hdr->mqtt_msg.dup = Dup ? 1 : 0; hdr->mqtt_msg.retain = Retain ? 1 : 0; - *(u_int*) hdr->mqtt_len = n; + l = (u_int*) hdr->mqtt_len; + *l = n; data += siz; /* variable header */