diff --git a/components/bt/bluedroid/api/esp_gatts_api.c b/components/bt/bluedroid/api/esp_gatts_api.c index 2b3b0ba80..80d89b30b 100644 --- a/components/bt/bluedroid/api/esp_gatts_api.c +++ b/components/bt/bluedroid/api/esp_gatts_api.c @@ -321,6 +321,7 @@ esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *l ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) { + *length = 0; return ESP_GATT_INVALID_HANDLE; } diff --git a/components/bt/bluedroid/stack/gatt/gatt_api.c b/components/bt/bluedroid/stack/gatt/gatt_api.c index cbc37e3aa..e6ea5b4f0 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -766,7 +766,8 @@ tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 * attr_handle); if ((p_decl = gatt_find_hdl_buffer_by_attr_handle(attr_handle)) == NULL) { - GATT_TRACE_ERROR("Service not created\n"); + GATT_TRACE_ERROR("Service not created\n"); + *length = 0; return GATT_INVALID_HANDLE; } diff --git a/components/bt/bluedroid/stack/gatt/gatt_db.c b/components/bt/bluedroid/stack/gatt/gatt_db.c index 5b822b25d..8a0511748 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_db.c +++ b/components/bt/bluedroid/stack/gatt/gatt_db.c @@ -783,10 +783,12 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle, if (p_db == NULL) { GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db is NULL.\n"); + *length = 0; return GATT_INVALID_PDU; } if (p_db->p_attr_list == NULL) { GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db->p_attr_list is NULL.\n"); + *length = 0; return GATT_INVALID_PDU; } if (length == NULL){ @@ -795,6 +797,7 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle, } if (value == NULL){ GATT_TRACE_ERROR("gatts_get_attribute_value Fail:value is NULL.\n"); + *length = 0; return GATT_INVALID_PDU; } @@ -814,19 +817,19 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle, *value = p_cur->p_value->attr_val.attr_val; return GATT_SUCCESS; } else { - GATT_TRACE_ERROR("gatts_get_attribute_value failed:the value length is 0"); - return GATT_INVALID_ATTR_LEN; + *length = 0; + return GATT_SUCCESS; } break; } } else { - if (p_cur->p_value->attr_val.attr_len != 0) { + if (p_cur->p_value && p_cur->p_value->attr_val.attr_len != 0) { *length = p_cur->p_value->attr_val.attr_len; *value = p_cur->p_value->attr_val.attr_val; return GATT_SUCCESS; } else { - GATT_TRACE_ERROR("gatts_get_attribute_value failed:the value length is 0"); - return GATT_INVALID_ATTR_LEN; + *length = 0; + return GATT_SUCCESS; } }