also fixed 'multiplier overflow' bug - YAY COMPILERS

This commit is contained in:
ladyada 2016-06-07 22:39:07 -04:00
parent 7e888e576a
commit 58f5d0cda6
2 changed files with 6 additions and 7 deletions

View File

@ -253,7 +253,7 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t timeout) {
rlen = readPacket(pbuff, 1, timeout);
if (rlen != 1) return 0;
//DEBUG_PRINT(F("Packet Type:\t")); DEBUG_PRINTBUFFER(pbuff, rlen);
DEBUG_PRINT(F("Packet Type:\t")); DEBUG_PRINTBUFFER(pbuff, rlen);
pbuff++;
uint32_t value = 0;
@ -265,12 +265,11 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t timeout) {
if (rlen != 1) return 0;
encodedByte = pbuff[0]; // save the last read val
pbuff++; // get ready for reading the next byte
uint32_t intermediate = encodedByte & 0x7F;
intermediate *= multiplier;
value += intermediate;
multiplier *= 128;
if (multiplier > 128*128*128) {
if (multiplier > (128UL*128UL*128UL)) {
DEBUG_PRINT(F("Malformed packet len\n"));
return 0;
}

View File

@ -70,7 +70,7 @@ class Adafruit_MQTT_FONA : public Adafruit_MQTT {
uint16_t readPacket(uint8_t *buffer, uint8_t maxlen, int16_t timeout) {
uint8_t *buffp = buffer;
DEBUG_PRINTLN(F("Reading a packet.."));
DEBUG_PRINTLN(F("Reading data.."));
if (!fona->TCPconnected()) return 0;
@ -81,9 +81,9 @@ class Adafruit_MQTT_FONA : public Adafruit_MQTT {
uint16_t avail;
while (fona->TCPconnected() && (timeout >= 0)) {
DEBUG_PRINT('.');
//DEBUG_PRINT('.');
while (avail = fona->TCPavailable()) {
DEBUG_PRINT('!');
//DEBUG_PRINT('!');
if (len + avail > maxlen) {
avail = maxlen - len;
@ -101,7 +101,7 @@ class Adafruit_MQTT_FONA : public Adafruit_MQTT {
//DEBUG_PRINTLN((uint8_t)c, HEX);
if (len == maxlen) { // we read all we want, bail
DEBUG_PRINT(F("Read packet:\t"));
DEBUG_PRINT(F("Read:\t"));
DEBUG_PRINTBUFFER(buffer, len);
return len;
}