From f715fa193665ec0555ad4e5b6c7cad9194d50652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Mu=CC=88ller?= Date: Fri, 12 Jan 2024 21:55:22 +0100 Subject: [PATCH 1/2] replace unsigned int by size_t --- src/PubSubClient.cpp | 14 +++++++------- src/PubSubClient.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 112403c0..93194462 100755 --- a/src/PubSubClient.cpp +++ b/src/PubSubClient.cpp @@ -441,13 +441,13 @@ boolean PubSubClient::publish(const char* topic, const char* payload, boolean re return publish(topic,(const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0,retained); } -boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) { +boolean PubSubClient::publish(const char* topic, const uint8_t* payload, size_t plength) { return publish(topic, payload, plength, false); } -boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) { +boolean PubSubClient::publish(const char* topic, const uint8_t* payload, size_t plength, boolean retained) { if (connected()) { - if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2+strnlen(topic, this->bufferSize) + plength) { + if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2 + strnlen(topic, this->bufferSize) + plength) { // Too long return false; } @@ -475,7 +475,7 @@ boolean PubSubClient::publish_P(const char* topic, const char* payload, boolean return publish_P(topic, (const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0, retained); } -boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) { +boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, size_t plength, boolean retained) { uint8_t llen = 0; uint8_t digit; unsigned int rc = 0; @@ -483,8 +483,8 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig unsigned int pos = 0; unsigned int i; uint8_t header; - unsigned int len; - int expectedLength; + size_t len; + size_t expectedLength; if (!connected()) { return false; @@ -523,7 +523,7 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig return (rc == expectedLength); } -boolean PubSubClient::beginPublish(const char* topic, unsigned int plength, boolean retained) { +boolean PubSubClient::beginPublish(const char* topic, size_t plength, boolean retained) { if (connected()) { // Send the header and variable length field size_t length = MQTT_MAX_HEADER_SIZE; diff --git a/src/PubSubClient.h b/src/PubSubClient.h index faec421c..6fb529d0 100755 --- a/src/PubSubClient.h +++ b/src/PubSubClient.h @@ -154,10 +154,10 @@ class PubSubClient : public Print { void disconnect(); boolean publish(const char* topic, const char* payload); boolean publish(const char* topic, const char* payload, boolean retained); - boolean publish(const char* topic, const uint8_t * payload, unsigned int plength); - boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained); + boolean publish(const char* topic, const uint8_t * payload, size_t plength); + boolean publish(const char* topic, const uint8_t * payload, size_t plength, boolean retained); boolean publish_P(const char* topic, const char* payload, boolean retained); - boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained); + boolean publish_P(const char* topic, const uint8_t * payload, size_t plength, boolean retained); // Start to publish a message. // This API: // beginPublish(...) @@ -166,7 +166,7 @@ class PubSubClient : public Print { // Allows for arbitrarily large payloads to be sent without them having to be copied into // a new buffer and held in memory at one time // Returns 1 if the message was started successfully, 0 if there was an error - boolean beginPublish(const char* topic, unsigned int plength, boolean retained); + boolean beginPublish(const char* topic, size_t plength, boolean retained); // Finish off this publish message (started with beginPublish) // Returns 1 if the packet was sent successfully, 0 if there was an error int endPublish(); From c7e3e47cce85bdf6491138e417fc961a398f14ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Mu=CC=88ller?= Date: Fri, 12 Jan 2024 23:09:49 +0100 Subject: [PATCH 2/2] replace unsigned int by size_t --- src/PubSubClient.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PubSubClient.h b/src/PubSubClient.h index 6fb529d0..520105ae 100755 --- a/src/PubSubClient.h +++ b/src/PubSubClient.h @@ -79,12 +79,12 @@ # ifdef __has_include # if __has_include() # include -# define MQTT_CALLBACK_SIGNATURE std::function callback +# define MQTT_CALLBACK_SIGNATURE std::function callback # else -# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int) +# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, size_t) # endif # else -# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int) +# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, size_t) # endif #define CHECK_STRING_LENGTH(l,s) if (l+2+strnlen(s, this->bufferSize) > this->bufferSize) {_client->stop();return false;}