From: Luiz Augusto von Dentz Date: Fri, 1 Apr 2022 21:32:53 +0000 (-0700) Subject: shared/gatt-db: Fix gatt_db_attribute_get_index X-Git-Tag: accepted/tizen/unified/20230608.164325~301 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44e835035dbebbcece5fc85fbd2ef4790b3c70b3;p=platform%2Fupstream%2Fbluez.git shared/gatt-db: Fix gatt_db_attribute_get_index gatt_db_attribute_get_index was calculating the index based on attrib->handle - service->attributes[0]->handle which doesn't work when there are gaps in between handles. Fixes: https://github.com/bluez/bluez/issues/326 Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index d85ed56..9d53708 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -1544,12 +1544,12 @@ static int gatt_db_attribute_get_index(struct gatt_db_attribute *attrib) return -1; service = attrib->service; - index = attrib->handle - service->attributes[0]->handle; - - if (index > (service->num_handles - 1)) - return -1; + for (index = 0; index < service->num_handles; index++) { + if (service->attributes[index] == attrib) + return index; + } - return index; + return -1; } static struct gatt_db_attribute *