Skip to content

Commit b831d10

Browse files
committed
Merge branch 'handle_empty_str' into 'main'
handle setting empty strings See merge request app-frameworks/esp-matter!694
2 parents 9aef5f4 + 8943861 commit b831d10

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

components/esp_matter/esp_matter_attribute_utils.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,10 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
12711271
if (attribute_type) {
12721272
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
12731273
}
1274-
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
1274+
size_t string_len = 0;
1275+
if (val->val.a.b) {
1276+
string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
1277+
}
12751278
size_t data_size_len = val->val.a.t - val->val.a.s;
12761279
if (string_len >= UINT8_MAX || data_size_len != 1) {
12771280
return ESP_ERR_INVALID_ARG;
@@ -1298,7 +1301,10 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
12981301
if (attribute_type) {
12991302
*attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
13001303
}
1301-
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
1304+
size_t string_len = 0;
1305+
if (val->val.a.b) {
1306+
string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
1307+
}
13021308
size_t data_size_len = val->val.a.t - val->val.a.s;
13031309
if (string_len >= UINT8_MAX || data_size_len != 2) {
13041310
return ESP_ERR_INVALID_ARG;
@@ -1926,11 +1932,15 @@ void val_print(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
19261932
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %" PRIu64 " **********", action,
19271933
endpoint_id, cluster_id, attribute_id, val->val.u64);
19281934
} else if (val->type == ESP_MATTER_VAL_TYPE_CHAR_STRING) {
1935+
const char *b = val->val.a.b ? (const char *)val->val.a.b : "(empty)";
1936+
uint16_t s = val->val.a.b ? s : strlen("(empty)");
19291937
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %.*s **********", action,
1930-
endpoint_id, cluster_id, attribute_id, val->val.a.s, val->val.a.b);
1938+
endpoint_id, cluster_id, attribute_id, s, b);
19311939
} else if (val->type == ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING) {
1940+
const char *b = val->val.a.b ? (const char *)val->val.a.b : "(empty)";
1941+
uint16_t s = val->val.a.b ? s : strlen("(empty)");
19321942
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %.*s **********", action,
1933-
endpoint_id, cluster_id, attribute_id, val->val.a.s, val->val.a.b);
1943+
endpoint_id, cluster_id, attribute_id, s, b);
19341944
} else {
19351945
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is <invalid type: %d> **********", action,
19361946
endpoint_id, cluster_id, attribute_id, val->type);

components/esp_matter/private/esp_matter_nvs.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ static esp_err_t nvs_store_val(const char *nvs_namespace, const char *attribute_
230230
if (val.val.a.b) {
231231
err = nvs_set_blob(handle, attribute_key, val.val.a.b, val.val.a.s);
232232
} else {
233-
err = ESP_OK;
233+
err = nvs_erase_key(handle, attribute_key);
234234
}
235+
nvs_commit(handle);
235236
} else {
236237
// This switch case handles primitive data types
237238
// always store values as primitive data type

0 commit comments

Comments
 (0)