diff --git a/components/bt/bluedroid/api/esp_gatts_api.c b/components/bt/bluedroid/api/esp_gatts_api.c index d40f2ac09a..dea4fabf3e 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 10f66db4b6..8fbb27f8bd 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -762,7 +762,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 46c5104c83..e5b6177077 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_db.c +++ b/components/bt/bluedroid/stack/gatt/gatt_db.c @@ -763,10 +763,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){ @@ -775,6 +777,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; } @@ -794,19 +797,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; } }