Empty string fix

This commit is contained in:
2025-07-20 20:55:14 -04:00
parent c363b2b7da
commit cb730557d0

View File

@@ -58,11 +58,15 @@ std::string ConfigManager::get_string(const char *key) {
nvs_open(NVS_FLASH_NAMESPACE, NVS_READONLY, &config_handle);
size_t required_size; // get size of the string
nvs_get_str(config_handle, key, nullptr, &required_size);
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_str(config_handle, key, nullptr, &required_size)) {
return "";
}
std::string str;
str.resize(required_size);
nvs_get_str(config_handle, key, str.data(), &required_size);
if (ESP_ERR_NVS_NOT_FOUND == nvs_get_str(config_handle, key, str.data(), &required_size)) {
return "";
}
nvs_close(config_handle);
return str;