From 2f91f1323d20519a34f0152d42102b3898435642 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 19 Aug 2019 11:26:27 +0300 Subject: [PATCH] Bluetooth: GATT: Remove dead code This fixes the dead code when parsing Find Information response since the index counter can never be zero, instead it checks there are any attributes found and if there nothing don't proceed with discovering which was the original intent of the now dead code. Fixes #18384 Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/host/gatt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index d352420ce8a..f8f77e2b6eb 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -2492,8 +2492,15 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err, goto done; } + length--; + + /* Check if there is a least one descriptor in the response */ + if (length < len) { + goto done; + } + /* Parse descriptors found */ - for (i = (length - 1) / len, pdu = rsp->info; i != 0; + for (i = length / len, pdu = rsp->info; i != 0; i--, pdu = (const u8_t *)pdu + len) { struct bt_gatt_attr *attr; @@ -2549,11 +2556,6 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err, } } - /* Stop if could not parse the whole PDU */ - if (i) { - goto done; - } - gatt_discover_next(conn, handle, params); return;