Skip to content

Commit

Permalink
Merge branch 'fix/attribute_metadata_size' into 'main'
Browse files Browse the repository at this point in the history
bugfix: fix the decreasing of attribute metadate size after reboot

See merge request app-frameworks/esp-matter!512
  • Loading branch information
chshu committed Oct 18, 2023
2 parents 79dfcc7 + b262e17 commit 1fa0968
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/esp_matter/private/esp_matter_nvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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 {
Expand Down

0 comments on commit 1fa0968

Please sign in to comment.