hog-lib: Fix scan-build error
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 16 Aug 2022 22:04:12 +0000 (15:04 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This fixes the following errors:
profiles/input/hog-lib.c:600:19: warning: Access to field 'handle'
results in a dereference of a null pointer (loaded from variable 'chr')
        report->handle = chr->handle;
                         ^~~~~~~~~~~
profiles/input/hog-lib.c:637:11: warning: Access to field 'value_handle'
results in a dereference of a null pointer (loaded from variable 'chr')
                start = chr->value_handle + 1;
                        ^~~~~~~~~~~~~~~~~
profiles/input/hog-lib.c:1240:11: warning: Access to field 'value_handle'
results in a dereference of a null pointer (loaded from variable 'chr')
                start = chr->value_handle + 1;
                        ^~~~~~~~~~~~~~~~~

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/input/hog-lib.c

index 6752280..0d87c4f 100755 (executable)
@@ -590,6 +590,9 @@ static struct report *report_new(struct bt_hog *hog, struct gatt_char *chr)
        struct report *report;
        GSList *l;
 
+       if (!chr)
+               return NULL;
+
        /* Skip if report already exists */
        l = g_slist_find_custom(hog->reports, chr, report_chrc_cmp);
        if (l)
@@ -630,6 +633,9 @@ static void external_service_char_cb(uint8_t status, GSList *chars,
                chr = l->data;
                next = l->next ? l->next->data : NULL;
 
+               if (!chr)
+                       continue;
+
                DBG("0x%04x UUID: %s properties: %02x",
                                chr->handle, chr->uuid, chr->properties);
 
@@ -1232,6 +1238,9 @@ static void char_discovered_cb(uint8_t status, GSList *chars, void *user_data)
                chr = l->data;
                next = l->next ? l->next->data : NULL;
 
+               if (!chr)
+                       continue;
+
                DBG("0x%04x UUID: %s properties: %02x",
                                chr->handle, chr->uuid, chr->properties);