From 04cd5d2a97c887938ff53b621a4a4a6cc7eec967 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 6 Mar 2025 10:56:58 -0500 Subject: [PATCH] btdev: Fix scan-build warnings This fixes the following scan-build warnings: emulator/btdev.c:1126:10: warning: Although the value stored to 'conn' is used in the enclosing expression, the value is never actually read from 'conn' [deadcode.DeadStores] 1126 | while ((conn = queue_find(dev->conns, match_handle, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1127 | UINT_TO_PTR(handle)))) | ~~~~~~~~~~~~~~~~~~~~ emulator/btdev.c:1413:24: warning: Access to field 'link' results in a dereference of a null pointer (loaded from variable 'conn') [core.NullDereference] 1413 | pending_conn_del(dev, conn->link->dev); | ^~~~~~~~~~ emulator/btdev.c:1535:13: warning: Access to field 'dev' results in a dereference of a null pointer (loaded from variable 'conn') [core.NullDereference] 1535 | send_event(conn->dev, BT_HCI_EVT_AUTH_COMPLETE, &ev, sizeof(ev)); | ^~~~~~~~~ --- emulator/btdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index ec52c5242..77d44ad84 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1123,8 +1123,7 @@ static struct btdev_conn *conn_new(struct btdev *dev, uint16_t handle, { struct btdev_conn *conn; - while ((conn = queue_find(dev->conns, match_handle, - UINT_TO_PTR(handle)))) + while (queue_find(dev->conns, match_handle, UINT_TO_PTR(handle))) handle++; conn = new0(struct btdev_conn, 1); @@ -1410,8 +1409,6 @@ static int cmd_add_sco_conn(struct btdev *dev, const void *data, uint8_t len) cc.encr_mode = 0x00; done: - pending_conn_del(dev, conn->link->dev); - send_event(dev, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc)); return 0; @@ -1527,9 +1524,12 @@ static void auth_complete(struct btdev_conn *conn, uint8_t status) { struct bt_hci_evt_auth_complete ev; + if (!conn) + return; + memset(&ev, 0, sizeof(ev)); - ev.handle = conn ? cpu_to_le16(conn->handle) : 0x0000; + ev.handle = cpu_to_le16(conn->handle); ev.status = status; send_event(conn->dev, BT_HCI_EVT_AUTH_COMPLETE, &ev, sizeof(ev)); -- 2.47.3