Skip to content

Commit

Permalink
Merge branch 'handle_empty_str' into 'main'
Browse files Browse the repository at this point in the history
handle setting empty strings

See merge request app-frameworks/esp-matter!694
  • Loading branch information
dhrishi committed Apr 25, 2024
2 parents 9aef5f4 + 8943861 commit b831d10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions components/esp_matter/esp_matter_attribute_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,10 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
if (attribute_type) {
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
}
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
size_t string_len = 0;
if (val->val.a.b) {
string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
}
size_t data_size_len = val->val.a.t - val->val.a.s;
if (string_len >= UINT8_MAX || data_size_len != 1) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -1298,7 +1301,10 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
if (attribute_type) {
*attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
}
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
size_t string_len = 0;
if (val->val.a.b) {
string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
}
size_t data_size_len = val->val.a.t - val->val.a.s;
if (string_len >= UINT8_MAX || data_size_len != 2) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -1926,11 +1932,15 @@ void val_print(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %" PRIu64 " **********", action,
endpoint_id, cluster_id, attribute_id, val->val.u64);
} else if (val->type == ESP_MATTER_VAL_TYPE_CHAR_STRING) {
const char *b = val->val.a.b ? (const char *)val->val.a.b : "(empty)";
uint16_t s = val->val.a.b ? s : strlen("(empty)");
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %.*s **********", action,
endpoint_id, cluster_id, attribute_id, val->val.a.s, val->val.a.b);
endpoint_id, cluster_id, attribute_id, s, b);
} else if (val->type == ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING) {
const char *b = val->val.a.b ? (const char *)val->val.a.b : "(empty)";
uint16_t s = val->val.a.b ? s : strlen("(empty)");
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %.*s **********", action,
endpoint_id, cluster_id, attribute_id, val->val.a.s, val->val.a.b);
endpoint_id, cluster_id, attribute_id, s, b);
} else {
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is <invalid type: %d> **********", action,
endpoint_id, cluster_id, attribute_id, val->type);
Expand Down
3 changes: 2 additions & 1 deletion components/esp_matter/private/esp_matter_nvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ static esp_err_t nvs_store_val(const char *nvs_namespace, const char *attribute_
if (val.val.a.b) {
err = nvs_set_blob(handle, attribute_key, val.val.a.b, val.val.a.s);
} else {
err = ESP_OK;
err = nvs_erase_key(handle, attribute_key);
}
nvs_commit(handle);
} else {
// This switch case handles primitive data types
// always store values as primitive data type
Expand Down

0 comments on commit b831d10

Please sign in to comment.