1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-27 15:01:49 +03:00

Fixes issue with client erroneously reading a byte from 0 length packets

This commit is contained in:
Lucas Jandrew
2020-02-24 01:10:09 -05:00
parent 0b8488d9bf
commit 44199a17ee
2 changed files with 21 additions and 6 deletions

View File

@ -53,6 +53,9 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
uint16_t len = 0;
int16_t t = timeout;
if (maxlen == 0) { // handle zero-length packets
return 0;
}
while (client->connected() && (timeout >= 0)) {
//DEBUG_PRINT('.');
@ -64,10 +67,6 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
//DEBUG_PRINTLN((uint8_t)c, HEX);
len++;
if (maxlen == 0) { // handle zero-length packets
return 0;
}
if (len == maxlen) { // we read all we want, bail
DEBUG_PRINT(F("Read data:\t"));
DEBUG_PRINTBUFFER(buffer, len);