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 <haavard.reierstad@nordicsemi.no>
This commit is contained in:
parent
f7b2638165
commit
43149c1056
|
@ -3484,19 +3484,19 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn,
|
|||
|
||||
/* Check if attribute is a characteristic declaration */
|
||||
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC)) {
|
||||
uint8_t properties;
|
||||
uint8_t properties = 0;
|
||||
ssize_t len;
|
||||
|
||||
CHECKIF(!attr->read) {
|
||||
if (!attr->read) {
|
||||
LOG_ERR("Read method not set");
|
||||
return false;
|
||||
}
|
||||
/* The charactestic properties is the first byte of the attribute value */
|
||||
len = attr->read(NULL, attr, &properties, 1, 0);
|
||||
len = attr->read(NULL, attr, &properties, sizeof(properties), 0);
|
||||
if (len < 0) {
|
||||
LOG_ERR("Failed to read attribute (err %zd)", len);
|
||||
return false;
|
||||
} else if (len != 1) {
|
||||
} else if (len != sizeof(properties)) {
|
||||
LOG_ERR("Invalid read length: %zd", len);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue