Skip to content

Commit

Permalink
corrected string and char array length
Browse files Browse the repository at this point in the history
  • Loading branch information
kleini committed Mar 24, 2019
1 parent 050cc8b commit 107fbdf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Homie/Boot/BootConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void BootConfig::setup() {
WiFi.mode(WIFI_AP_STA);

char apName[MAX_WIFI_SSID_LENGTH];
strlcpy(apName, Interface::get().brand, MAX_WIFI_SSID_LENGTH - 1 - MAX_MAC_STRING_LENGTH);
strlcpy(apName, Interface::get().brand, MAX_WIFI_SSID_LENGTH - 1 - (MAX_MAC_STRING_LENGTH - 1));
strcat_P(apName, PSTR("-"));
strcat(apName, DeviceId::get());

Expand Down
2 changes: 1 addition & 1 deletion src/Homie/Utils/DeviceId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ char DeviceId::_deviceId[]; // need to define the static variable
void DeviceId::generate() {
uint8_t mac[6];
WiFi.macAddress(mac);
snprintf(DeviceId::_deviceId, MAX_MAC_STRING_LENGTH+1 , "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
snprintf(DeviceId::_deviceId, MAX_MAC_STRING_LENGTH, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}

const char* DeviceId::get() {
Expand Down
2 changes: 1 addition & 1 deletion src/Homie/Utils/DeviceId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class DeviceId {
static const char* get();

private:
static char _deviceId[MAX_MAC_STRING_LENGTH + 1];
static char _deviceId[MAX_MAC_STRING_LENGTH];
};
} // namespace HomieInternals
2 changes: 1 addition & 1 deletion src/Homie/Utils/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool Helpers::validateMacAddress(const char* mac) {
}
++mac;
}
return (i == MAX_MAC_STRING_LENGTH && s == 5);
return (i == MAX_MAC_LENGTH * 2 && s == 5);
}

bool Helpers::validateMd5(const char* md5) {
Expand Down
2 changes: 1 addition & 1 deletion src/Homie/Utils/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,5 @@ ConfigValidationResult Validation::_validateConfigSettings(const JsonObject& obj
// }
// ++mac;
// }
// return (i == MAX_MAC_STRING_LENGTH && s == 5);
// return (i == MAX_MAC_LENGTH * 2 && s == 5);
// }

0 comments on commit 107fbdf

Please sign in to comment.