From 40a90f4e98fe0f2fa2da68b99ae136947d3d5189 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 21 Sep 2022 14:52:53 -0700 Subject: shared/gatt-db: Fix scan-build warnings This fixes the following warnings: src/shared/gatt-db.c:1339:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn] return data.num_of_res; ^~~~~~~~~~~~~~~~~~~~~~ src/shared/gatt-db.c:725:5: warning: Access to field 'handle' results in a dereference of a null pointer service->attributes[0]->handle == handle) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/shared/gatt-db.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 32cbf6cdc..ba47c75ff 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -709,21 +709,24 @@ struct gatt_db_attribute *gatt_db_insert_service(struct gatt_db *db, if (service) { const bt_uuid_t *type; bt_uuid_t value; + struct gatt_db_attribute *attr = service->attributes[0]; + + if (!attr) + return NULL; if (primary) type = &primary_service_uuid; else type = &secondary_service_uuid; - gatt_db_attribute_get_service_uuid(service->attributes[0], - &value); + gatt_db_attribute_get_service_uuid(attr, &value); /* Check if service match */ - if (!bt_uuid_cmp(&service->attributes[0]->uuid, type) && + if (!bt_uuid_cmp(&attr->uuid, type) && !bt_uuid_cmp(&value, uuid) && service->num_handles == num_handles && - service->attributes[0]->handle == handle) - return service->attributes[0]; + attr->handle == handle) + return attr; return NULL; } @@ -1328,6 +1331,7 @@ unsigned int gatt_db_find_by_type_value(struct gatt_db *db, { struct find_by_type_value_data data; + memset(&data, 0, sizeof(data)); data.func = func; data.user_data = user_data; data.value = value; -- cgit v1.2.1