From 18ef73e949d49f7345f2a6f3e51c029c7459e0a5 Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Tue, 25 May 2021 21:17:48 +0200 Subject: [PATCH] fix(core): Fix memory copy bug for GATT With newlib_libc enabled, a warning was printed for this memcpy. uuid is a `bt_uuid_128`, while BT_UUID_GATT_CCC is only `bt_uuid_16`. Fixes #808. Full warning: [53/272] Building C object CMakeFiles/app.dir/src/split/bluetooth/central.c.obj In file included from /home/okke/.local/zephyr-sdk-0.11.2/arm-zephyr-eabi/arm-zephyr-eabi/sys-include/string.h:180, from /home/okke/dev/zmk/zephyr/include/bluetooth/bluetooth.h:21, from ../../src/split/bluetooth/central.c:9: ../../src/split/bluetooth/central.c: In function 'split_central_discovery_func': ../../src/split/bluetooth/central.c:130:9: warning: '__builtin_memcpy' forming offset [5, 17] is out of the bounds [0, 4] of object '({anonymous})' with type 'struct bt_uuid_16[1]' [-Warray-bounds] 130 | memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); | ^~~~~~ /home/okke/dev/zmk/zephyr/include/bluetooth/uuid.h:72:45: note: '({anonymous})' declared here 72 | ((struct bt_uuid *) ((struct bt_uuid_16[]) {BT_UUID_INIT_16(value)})) | ^ /home/okke/dev/zmk/zephyr/include/bluetooth/uuid.h:372:2: note: in expansion of macro 'BT_UUID_DECLARE_16' 372 | BT_UUID_DECLARE_16(BT_UUID_GATT_CCC_VAL) | ^~~~~~~~~~~~~~~~~~ ../../src/split/bluetooth/central.c:130:23: note: in expansion of macro 'BT_UUID_GATT_CCC' 130 | memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); --- app/src/split/bluetooth/central.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index a56b0b81..680e7a4e 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -127,7 +127,7 @@ static uint8_t split_central_discovery_func(struct bt_conn *conn, const struct b } } else if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID))) { - memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); + memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(struct bt_uuid_16)); discover_params.uuid = &uuid.uuid; discover_params.start_handle = attr->handle + 2; discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;