Skip to content

Commit

Permalink
bluetooth: host: Fix alignment of gatt_chrc
Browse files Browse the repository at this point in the history
The following warning is issued by clang:

warning: field  within 'struct gatt_chrc' is less aligned than 'union
gatt_chrc::(anonymous at subsys/bluetooth/host/gatt.c:1859:2)' and
is usually due to 'struct gatt_chrc' being packed, which can lead
to unaligned accesses [-Wunaligned-access]

This is due to the fact that the uint16_t uuid field requires 2-byte
alignment but it is not marked as packed. Since the enclosing struct is
indeed packed, the required alignment is not guaranteed and so clang
complains. Fix it by ensuring that the union is marked as packed too.

Signed-off-by: Carles Cufi <[email protected]>
  • Loading branch information
carlescufi authored and jhedberg committed Apr 23, 2024
1 parent f18ea95 commit a1dd9a5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ struct gatt_chrc {
union {
uint16_t uuid16;
uint8_t uuid[16];
};
} __packed;
} __packed;

uint16_t bt_gatt_attr_value_handle(const struct bt_gatt_attr *attr)
Expand Down

0 comments on commit a1dd9a5

Please sign in to comment.