knolleary/pubsubclient

esp8266 crashes when using payload in PROGMEM (v2.8)

absalom-muc opened this issue · 1 comments

SInce the latest update (v2.8)
publish_P(const char* topic, const char* payload, boolean retained)
crashes when using it with payload located in PROGMEM.

Example: Using of
client.publish_P("outTopic_P", PSTR("test"), true);
was possible in v2.7, but no longer in v2.8. (tested with mqtt_esp8266)

Seems that the problem is in line 475
return publish_P(topic, (const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0, retained);
Maybe better use strnlen_P.

Thank you.

@absalom-muc Thanks for your post. I encountered the same problem and your suggested fix works for me.

I found another pull request to fix this here: https://github.com/knolleary/pubsubclient/pull/745/commits, but the build failed caused by an incorrect include of #include <avr/pgmspace.h> for ESP8266. I've added a comment to fix that, otherwise I can create a new pull request on master.

@knolleary what do you prefer to proceed?