From b262e17416a4cd5b827258792886fa17e3fe681b Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 13 Oct 2023 10:31:07 +0800 Subject: [PATCH] esp-matter: fix the decreasing of attribute metadate size after reboot --- components/esp_matter/private/esp_matter_nvs.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/private/esp_matter_nvs.cpp b/components/esp_matter/private/esp_matter_nvs.cpp index 64299c2c6..e5bba6db9 100644 --- a/components/esp_matter/private/esp_matter_nvs.cpp +++ b/components/esp_matter/private/esp_matter_nvs.cpp @@ -48,15 +48,18 @@ esp_err_t get_val_from_nvs(uint16_t endpoint_id, uint32_t cluster_id, uint32_t a val.type == ESP_MATTER_VAL_TYPE_ARRAY) { size_t len = 0; if ((err = nvs_get_blob(handle, attribute_key, NULL, &len)) == ESP_OK) { + // This function will only be called when recovering the non-volatile attributes during reboot + // Add we should not decrease the size of the attribute value + len = std::max(len, static_cast(val.val.a.s)); uint8_t *buffer = (uint8_t *)esp_matter_mem_calloc(1, len); if (!buffer) { err = ESP_ERR_NO_MEM; } else { - nvs_get_blob(handle, attribute_key, buffer, &len); val.val.a.b = buffer; val.val.a.n = len; val.val.a.t = len + (val.val.a.t - val.val.a.s); val.val.a.s = len; + nvs_get_blob(handle, attribute_key, buffer, &len); } } } else {