Skip to content

Commit 0389a63

Browse files
committed
Bluetooth: host: refactor bt_gatt_is_subscribed
Refactors `bt_gatt_is_subscribed` by changing a CHECKIF to an if statement to avoid undefined behavior if CHECKIFs are "disabled". Uses sizeof(a uint8_t) instead of 1 to avoid magic numbers. Initializes `properties` to 0 to avoid undefined behavior. Signed-off-by: Håvard Reierstad <[email protected]>
1 parent 23fb3b7 commit 0389a63

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,19 +3475,19 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn,
34753475

34763476
/* Check if attribute is a characteristic declaration */
34773477
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC)) {
3478-
uint8_t properties;
3478+
uint8_t properties = 0;
34793479
ssize_t len;
34803480

3481-
CHECKIF(!attr->read) {
3481+
if (!attr->read) {
34823482
LOG_ERR("Read method not set");
34833483
return false;
34843484
}
34853485
/* The charactestic properties is the first byte of the attribute value */
3486-
len = attr->read(NULL, attr, &properties, 1, 0);
3486+
len = attr->read(NULL, attr, &properties, sizeof(properties), 0);
34873487
if (len < 0) {
34883488
LOG_ERR("Failed to read attribute (err %zd)", len);
34893489
return false;
3490-
} else if (len != 1) {
3490+
} else if (len != sizeof(properties)) {
34913491
LOG_ERR("Invalid read length: %zd", len);
34923492
return false;
34933493
}

0 commit comments

Comments
 (0)