Skip to content

Commit 0c3c0b3

Browse files
committed
Removed some wrong conditions
1 parent b733398 commit 0c3c0b3

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/mqtt.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,6 @@ static int unpack_mqtt_connect(u8 *buf, struct mqtt_packet *pkt, usize len) {
256256
if (pkt->connect.bits.password == 1)
257257
unpack_string16(&buf, &pkt->connect.payload.password);
258258

259-
if (!pkt->connect.payload.will_topic
260-
|| !pkt->connect.payload.will_message
261-
|| !pkt->connect.payload.username
262-
|| !pkt->connect.payload.password)
263-
return -MQTT_ERR;
264-
265259
return MQTT_OK;
266260
}
267261

@@ -306,21 +300,19 @@ static int unpack_mqtt_publish(u8 *buf, struct mqtt_packet *pkt, usize len) {
306300
if (!pkt->publish.topic)
307301
return -MQTT_ERR;
308302

309-
u64 message_len = len;
310-
311303
/* Read packet id */
312304
if (pkt->header.bits.qos > AT_MOST_ONCE) {
313305
pkt->publish.pkt_id = unpack_integer(&buf, 'H');
314-
message_len -= sizeof(u16);
306+
len -= sizeof(u16);
315307
}
316308

317309
/*
318310
* Message len is calculated subtracting the length of the variable header
319311
* from the Remaining Length field that is in the Fixed Header
320312
*/
321-
message_len -= (sizeof(u16) + pkt->publish.topiclen);
322-
pkt->publish.payloadlen = message_len;
323-
pkt->publish.payload = unpack_bytes(&buf, message_len);
313+
len -= (sizeof(u16) + pkt->publish.topiclen);
314+
pkt->publish.payloadlen = len;
315+
pkt->publish.payload = unpack_bytes(&buf, len);
324316

325317
if (!pkt->publish.payload)
326318
return -MQTT_ERR;

0 commit comments

Comments
 (0)