[PATCH BlueZ] shared/gatt-db: Fix gatt_db_attribute_get_index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

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
---
 src/shared/gatt-db.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index be07cdbe4..4f5d10b57 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1537,12 +1537,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 *
-- 
2.35.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux