Skip to content

Commit 43149c1

Browse files
HaavardReinashif
authored andcommitted
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 f7b2638 commit 43149c1

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
@@ -3484,19 +3484,19 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn,
34843484

34853485
/* Check if attribute is a characteristic declaration */
34863486
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC)) {
3487-
uint8_t properties;
3487+
uint8_t properties = 0;
34883488
ssize_t len;
34893489

3490-
CHECKIF(!attr->read) {
3490+
if (!attr->read) {
34913491
LOG_ERR("Read method not set");
34923492
return false;
34933493
}
34943494
/* The charactestic properties is the first byte of the attribute value */
3495-
len = attr->read(NULL, attr, &properties, 1, 0);
3495+
len = attr->read(NULL, attr, &properties, sizeof(properties), 0);
34963496
if (len < 0) {
34973497
LOG_ERR("Failed to read attribute (err %zd)", len);
34983498
return false;
3499-
} else if (len != 1) {
3499+
} else if (len != sizeof(properties)) {
35003500
LOG_ERR("Invalid read length: %zd", len);
35013501
return false;
35023502
}

0 commit comments

Comments
 (0)