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:
2026-07-07 10:42:51 +03:00
co-authored by Claude Sonnet 4.6
parent 9e415de7bc
commit 67da788738
+2 -2
View File
@@ -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;
} }