fix(NvsMigration): check nvs_get_str return value before constructing String
nvsReadString previously ignored the error code from nvs_get_str and passed an uninitialised or garbage buffer to String() on failure. Now returns an empty string if the read fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -58,8 +58,8 @@ static String nvsReadString(nvs_handle_t handle, const char* key) {
|
|||||||
if (err != ESP_OK || len == 0) return "";
|
if (err != ESP_OK || len == 0) return "";
|
||||||
|
|
||||||
char* buf = new char[len];
|
char* buf = new char[len];
|
||||||
nvs_get_str(handle, key, buf, &len);
|
esp_err_t readErr = nvs_get_str(handle, key, buf, &len);
|
||||||
String result(buf);
|
String result = (readErr == ESP_OK) ? String(buf) : "";
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user