From 8f8446784671c0d8f2060841f3f92d3b81d5f227 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 13 Oct 2023 17:52:36 +0800 Subject: [PATCH] bugfix: fix the decreasing of attribute metadate size after reboot --- components/esp_matter/esp_matter_core.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index b6ed40bca..d78d46183 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -1514,16 +1514,19 @@ esp_err_t get_val_from_nvs(attribute_t *attribute, esp_matter_attr_val_t *val) current_attribute->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->type = current_attribute->val.type; val->val.a.b = buffer; val->val.a.s = len; val->val.a.n = len; val->val.a.t = len + (current_attribute->val.val.a.t - current_attribute->val.val.a.s); + nvs_get_blob(handle, attribute_key, buffer, &len); } } } else {