Skip to content

Commit 97cc3a5

Browse files
authored
Merge pull request #4 from arduino-hmueller01/fix-Wsign-compare
fix compiler warning
2 parents 7b9768a + c7e3e47 commit 97cc3a5

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/PubSubClient.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ boolean PubSubClient::publish(const char* topic, const char* payload, boolean re
473473
return publish(topic,(const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0,retained);
474474
}
475475

476-
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) {
476+
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, size_t plength) {
477477
return publish(topic, payload, plength, false);
478478
}
479479

480-
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
480+
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, size_t plength, boolean retained) {
481481
if (connected()) {
482-
if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2+strnlen(topic, this->bufferSize) + plength) {
482+
if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2 + strnlen(topic, this->bufferSize) + plength) {
483483
// Too long
484484
return false;
485485
}
@@ -507,16 +507,16 @@ boolean PubSubClient::publish_P(const char* topic, const char* payload, boolean
507507
return publish_P(topic, (const uint8_t*)payload, payload ? strnlen_P(payload, this->bufferSize) : 0, retained);
508508
}
509509

510-
boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
510+
boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, size_t plength, boolean retained) {
511511
uint8_t llen = 0;
512512
uint8_t digit;
513513
unsigned int rc = 0;
514514
uint16_t tlen;
515515
unsigned int pos = 0;
516516
unsigned int i;
517517
uint8_t header;
518-
unsigned int len;
519-
int expectedLength;
518+
size_t len;
519+
size_t expectedLength;
520520

521521
if (!connected()) {
522522
return false;
@@ -555,7 +555,7 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig
555555
return (rc == expectedLength);
556556
}
557557

558-
boolean PubSubClient::beginPublish(const char* topic, unsigned int plength, boolean retained) {
558+
boolean PubSubClient::beginPublish(const char* topic, size_t plength, boolean retained) {
559559
if (connected()) {
560560
// Send the header and variable length field
561561
uint16_t length = MQTT_MAX_HEADER_SIZE;

src/PubSubClient.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@
7979
# ifdef __has_include
8080
# if __has_include(<functional>)
8181
# include <functional>
82-
# define MQTT_CALLBACK_SIGNATURE std::function<void(char*, uint8_t*, unsigned int)> callback
82+
# define MQTT_CALLBACK_SIGNATURE std::function<void(char*, uint8_t*, size_t)> callback
8383
# else
84-
# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
84+
# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, size_t)
8585
# endif
8686
# else
87-
# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
87+
# define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, size_t)
8888
# endif
8989

9090
#define CHECK_STRING_LENGTH(l,s) if (l+2+strnlen(s, this->bufferSize) > this->bufferSize) {_client->stop();return false;}
@@ -154,10 +154,10 @@ class PubSubClient : public Print {
154154
void disconnect();
155155
boolean publish(const char* topic, const char* payload);
156156
boolean publish(const char* topic, const char* payload, boolean retained);
157-
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
158-
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
157+
boolean publish(const char* topic, const uint8_t * payload, size_t plength);
158+
boolean publish(const char* topic, const uint8_t * payload, size_t plength, boolean retained);
159159
boolean publish_P(const char* topic, const char* payload, boolean retained);
160-
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
160+
boolean publish_P(const char* topic, const uint8_t * payload, size_t plength, boolean retained);
161161
// Start to publish a message.
162162
// This API:
163163
// beginPublish(...)
@@ -166,7 +166,7 @@ class PubSubClient : public Print {
166166
// Allows for arbitrarily large payloads to be sent without them having to be copied into
167167
// a new buffer and held in memory at one time
168168
// Returns 1 if the message was started successfully, 0 if there was an error
169-
boolean beginPublish(const char* topic, unsigned int plength, boolean retained);
169+
boolean beginPublish(const char* topic, size_t plength, boolean retained);
170170
// Finish off this publish message (started with beginPublish)
171171
// Returns 1 if the packet was sent successfully, 0 if there was an error
172172
int endPublish();

0 commit comments

Comments
 (0)