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

Small bug correction: use strnlen_P and not strnlen #1004

Open gcog33 opened 1 year ago

gcog33 commented 1 year ago

In the file pubsubclient/src/PubSubClient.cpp In line 475 there is a small bug:

boolean PubSubClient::publish_P(const char* topic, const char* payload, boolean retained) {
    return publish_P(topic, (const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0, retained);
}

The function strnlen must be replaced by strnlen_P because the payload is in program memory (PROGMEM)