Skip to content

Removed all occurences of pgm_read_byte #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Adafruit_MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p[0] = MQTT_CONN_CLEANSESSION;

// set the will flags if needed
if (will_topic && pgm_read_byte(will_topic) != 0) {
if (will_topic && will_topic[0] != '\0') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eutill Why are you comparing \0 (null char.) here instead of 0 (int) from the previous will set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't know that comparing to 0 (int) was equivalent for checking for null-termination.

Please feel free to commit on this.


p[0] |= MQTT_CONN_WILLFLAG;

Expand All @@ -592,9 +592,9 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {

}

if (pgm_read_byte(username) != 0)
if (username[0] != '\0')
p[0] |= MQTT_CONN_USERNAMEFLAG;
if (pgm_read_byte(password) != 0)
if (password[0] != '\0')
p[0] |= MQTT_CONN_PASSWORDFLAG;
p++;

Expand All @@ -606,7 +606,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
if(MQTT_PROTOCOL_LEVEL == 3) {
p = stringprint(p, clientid, 23); // Limit client ID to first 23 characters.
} else {
if (pgm_read_byte(clientid) != 0) {
if (clientid[0] != '\0') {
p = stringprint(p, clientid);
} else {
p[0] = 0x0;
Expand All @@ -617,15 +617,15 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
}
}

if (will_topic && pgm_read_byte(will_topic) != 0) {
if (will_topic && will_topic[0] != '\0') {
p = stringprint(p, will_topic);
p = stringprint(p, will_payload);
}

if (pgm_read_byte(username) != 0) {
if (username[0] != '\0') {
p = stringprint(p, username);
}
if (pgm_read_byte(password) != 0) {
if (password[0] != '\0') {
p = stringprint(p, password);
}

Expand Down