Skip to content

Commit 4adabb4

Browse files
Thalleydanieldegrasse
authored andcommitted
Bluetooth: BAP: Use IN_RANGE in bt_bap_base_get_base_from_ad
This simplyfies the checks in the function a bit, and makes Sonarcloud happy. Signed-off-by: Emil Gydesen <[email protected]>
1 parent c8ac20f commit 4adabb4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

subsys/bluetooth/audio/bap_base.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const struct bt_bap_base *bt_bap_base_get_base_from_ad(const struct bt_data *ad)
148148
/* Pull all data to verify that the result BASE is valid */
149149
base_pull_pd(&net_buf);
150150
subgroup_count = net_buf_simple_pull_u8(&net_buf);
151-
if (subgroup_count == 0 || subgroup_count > BASE_SUBGROUP_MAX_COUNT) {
151+
if (!IN_RANGE(subgroup_count, 1U, BASE_SUBGROUP_MAX_COUNT)) {
152152
LOG_DBG("Invalid subgroup count: %u", subgroup_count);
153153

154154
return NULL;
@@ -164,7 +164,7 @@ const struct bt_bap_base *bt_bap_base_get_base_from_ad(const struct bt_data *ad)
164164
}
165165

166166
bis_count = base_pull_bis_count(&net_buf);
167-
if (bis_count == 0 || bis_count > BT_ISO_MAX_GROUP_ISO_COUNT) {
167+
if (!IN_RANGE(bis_count, 1U, BT_ISO_MAX_GROUP_ISO_COUNT)) {
168168
LOG_DBG("Subgroup[%u]: Invalid BIS count: %u", i, bis_count);
169169

170170
return NULL;
@@ -202,7 +202,7 @@ const struct bt_bap_base *bt_bap_base_get_base_from_ad(const struct bt_data *ad)
202202
}
203203

204204
bis_index = net_buf_simple_pull_u8(&net_buf);
205-
if (bis_index == 0 || bis_index > BT_ISO_BIS_INDEX_MAX) {
205+
if (!IN_RANGE(bis_index, 1U, BT_ISO_BIS_INDEX_MAX)) {
206206
LOG_DBG("Subgroup[%u]: Invalid BIS index: %u", i, bis_index);
207207

208208
return NULL;

0 commit comments

Comments
 (0)