knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

ESP8266 hangs while terminating Topic with 0 #970

Open RaHoni opened 1 year ago

RaHoni commented 1 year ago

I have an issue that when I receive a message from the broker the code hangs while terminating the moved topic with an 0. I located issue in the last line of the following snippet. Source

if (callback) {
  tl = (this->buffer[llen+1]<<8)+this->buffer[llen+2]; /* topic length in bytes */
  memmove(this->buffer+llen+2,this->buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */
  this->buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */

Surprisingly I can set it to every other value than 0.

As a workaround I simply memcpy the topic into the newly created var topic and null terminate this variable. Which actually works.

SDK is PlatformIO Core, version 6.1.4 Platform espressif8266 @ 4.0.1 (required: espressif8266) ├── framework-arduinoespressif8266 @ 3.30002.0 (required: platformio/framework-arduinoespressif8266 @ ~3.30002.0) ├── tool-esptool @ 1.413.0 (required: platformio/tool-esptool @ <2) ├── tool-esptoolpy @ 1.30000.201119 (required: platformio/tool-esptoolpy @ ~1.30000.0) ├── tool-mklittlefs @ 1.203.210628 (required: platformio/tool-mklittlefs @ ~1.203.0) ├── tool-mkspiffs @ 1.200.0 (required: platformio/tool-mkspiffs @ ~1.200.0) └── toolchain-xtensa @ 2.100300.210717 (required: platformio/toolchain-xtensa @ ~2.100300.0)

Libraries ├── AESLib @ 2.3.0 (required: suculent/AESLib @ ^2.2.1) ├── Crypto @ 0.4.0 (required: rweather/Crypto @ ^0.4.0) ├── ESP8266TrueRandom @ 1.0.0 (required: marvinroger/ESP8266TrueRandom @ ^1.0) └── PubSubClient @ 2.8.0 (required: knolleary/PubSubClient @ ^2.8)