shared/gatt-db: Fix scan-build warnings
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 21 Sep 2022 21:52:53 +0000 (14:52 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
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 <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/gatt-db.c

index a749286..78de38f 100644 (file)
@@ -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;