Reduce stack usage in loop(). No need to duplicate
topic string onto stack before giving it to callback() Just move it one byte in buffer to add space for 'C' string end \0x00
This commit is contained in:
parent
35ead348e3
commit
d724864095
@ -306,12 +306,10 @@ boolean PubSubClient::loop() {
|
|||||||
uint8_t type = buffer[0]&0xF0;
|
uint8_t type = buffer[0]&0xF0;
|
||||||
if (type == MQTTPUBLISH) {
|
if (type == MQTTPUBLISH) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2];
|
uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2]; /* topic length in bytes */
|
||||||
char topic[tl+1];
|
memmove(buffer+llen+2,buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */
|
||||||
for (uint16_t i=0;i<tl;i++) {
|
buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */
|
||||||
topic[i] = buffer[llen+3+i];
|
char *topic = (char*) buffer+llen+2;
|
||||||
}
|
|
||||||
topic[tl] = 0;
|
|
||||||
// msgId only present for QOS>0
|
// msgId only present for QOS>0
|
||||||
if ((buffer[0]&0x06) == MQTTQOS1) {
|
if ((buffer[0]&0x06) == MQTTQOS1) {
|
||||||
msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
|
msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user