Skip to content

Commit 2ec7a46

Browse files
alwa-nordiccarlescufi
authored andcommitted
Bluetooth: Assert alignof bt_addr types
I got some feedback about confusion as to why the bt_addr types are not packed. This commit adds a note about it. This commit also adds a check for the alignof of the structs to verify the statement 'their members are bytes or byte arrays' to thoroughly prove that the struct is effectively as-if packed. Signed-off-by: Aleksander Wasaznik <[email protected]>
1 parent 796fc9d commit 2ec7a46

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/bluetooth/common/dummy.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* SPDX-License-Identifier: Apache-2.0
1010
*/
1111

12+
#include <stdalign.h>
13+
1214
#include <zephyr/kernel.h>
1315
#include <zephyr/bluetooth/bluetooth.h>
1416

@@ -18,9 +20,15 @@
1820
* their members are bytes or byte arrays, the size is. They must not be padded
1921
* by the compiler, otherwise the on-wire packet will not map the packed
2022
* structure correctly.
23+
*
24+
* The bt_addr structs are not marked __packed because it's considered ugly by
25+
* some. But here is a proof that the structs have all the properties of, and
26+
* can be safely used as packed structs.
2127
*/
2228
BUILD_ASSERT(sizeof(bt_addr_t) == BT_ADDR_SIZE);
29+
BUILD_ASSERT(alignof(bt_addr_t) == 1);
2330
BUILD_ASSERT(sizeof(bt_addr_le_t) == BT_ADDR_LE_SIZE);
31+
BUILD_ASSERT(alignof(bt_addr_le_t) == 1);
2432

2533
#if defined(CONFIG_BT_HCI_HOST)
2634
/* The Bluetooth subsystem requires that higher priority events shall be given

0 commit comments

Comments
 (0)