1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 19:32:19 +01:00

fix(WiFi): Fix strncpy missing NULL terminator [-Werror=stringop-truncation] (#7668)

This commit is contained in:
Rodrigo Martín
2024-10-29 04:56:50 +01:00
committed by GitHub
parent aa0e155e22
commit abbd7faa64
4 changed files with 12 additions and 12 deletions

View File

@@ -297,8 +297,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) {
void WiFiComponent::clear_sta() { this->sta_.clear(); }
void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &password) {
SavedWifiSettings save{};
strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid));
strncpy(save.password, password.c_str(), sizeof(save.password));
snprintf(save.ssid, sizeof(save.ssid), "%s", ssid.c_str());
snprintf(save.password, sizeof(save.password), "%s", password.c_str());
this->pref_.save(&save);
// ensure it's written immediately
global_preferences->sync();