From: Luiz Augusto von Dentz Date: Wed, 21 Sep 2022 21:52:53 +0000 (-0700) Subject: shared/gatt-db: Fix scan-build warnings X-Git-Tag: accepted/tizen/unified/20230608.164325~78 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=689dafaf5bf68371b60f6245e89b9b3e78dbd70d;p=platform%2Fupstream%2Fbluez.git 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) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 a7492868..78de38f8 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -713,21 +713,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; } @@ -1335,6 +1338,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;