Skip to content

Commit 208908e

Browse files
Thalleynashif
authored andcommitted
Bluetooth: Audio: Shell: Fix long/int32_t value checks
In places where we verify that the value of the long variable does not exceed the limits of int32_t, we do actually not need to compare the values if the two types are the same size, which is often the case for 32-bit systems. This fixes a variety of coverity reported issues. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 4f77883 commit 208908e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

subsys/bluetooth/audio/shell/mcc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static int cmd_mcc_set_track_position(const struct shell *sh, size_t argc,
731731
return -ENOEXEC;
732732
}
733733

734-
if (!IN_RANGE(pos, INT32_MIN, INT32_MAX)) {
734+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(pos, INT32_MIN, INT32_MAX)) {
735735
shell_error(sh, "Invalid pos: %ld", pos);
736736

737737
return -ENOEXEC;
@@ -1105,7 +1105,7 @@ static int cmd_mcc_move_relative(const struct shell *sh, size_t argc,
11051105
return err;
11061106
}
11071107

1108-
if (!IN_RANGE(offset, INT32_MIN, INT32_MAX)) {
1108+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(offset, INT32_MIN, INT32_MAX)) {
11091109
shell_error(sh, "Invalid offset: %ld", offset);
11101110

11111111
return -ENOEXEC;
@@ -1211,7 +1211,7 @@ static int cmd_mcc_goto_segment(const struct shell *sh, size_t argc,
12111211
return err;
12121212
}
12131213

1214-
if (!IN_RANGE(segment, INT32_MIN, INT32_MAX)) {
1214+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(segment, INT32_MIN, INT32_MAX)) {
12151215
shell_error(sh, "Invalid segment: %ld", segment);
12161216

12171217
return -ENOEXEC;
@@ -1313,7 +1313,7 @@ static int cmd_mcc_goto_track(const struct shell *sh, size_t argc, char *argv[])
13131313
return err;
13141314
}
13151315

1316-
if (!IN_RANGE(track, INT32_MIN, INT32_MAX)) {
1316+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(track, INT32_MIN, INT32_MAX)) {
13171317
shell_error(sh, "Invalid track: %ld", track);
13181318

13191319
return -ENOEXEC;
@@ -1415,7 +1415,7 @@ static int cmd_mcc_goto_group(const struct shell *sh, size_t argc, char *argv[])
14151415
return err;
14161416
}
14171417

1418-
if (!IN_RANGE(group, INT32_MIN, INT32_MAX)) {
1418+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(group, INT32_MIN, INT32_MAX)) {
14191419
shell_error(sh, "Invalid group: %ld", group);
14201420

14211421
return -ENOEXEC;

subsys/bluetooth/audio/shell/media_controller.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static int cmd_media_set_track_position(const struct shell *sh, size_t argc,
576576
return -ENOEXEC;
577577
}
578578

579-
if (!IN_RANGE(position, INT32_MIN, INT32_MAX)) {
579+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(position, INT32_MIN, INT32_MAX)) {
580580
shell_error(sh, "Invalid position: %ld", position);
581581

582582
return -ENOEXEC;
@@ -865,7 +865,7 @@ static int cmd_media_move_relative(const struct shell *sh, size_t argc,
865865
return err;
866866
}
867867

868-
if (!IN_RANGE(offset, INT32_MIN, INT32_MAX)) {
868+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(offset, INT32_MIN, INT32_MAX)) {
869869
shell_error(sh, "Invalid offset: %ld", offset);
870870

871871
return -ENOEXEC;
@@ -976,7 +976,7 @@ static int cmd_media_goto_segment(const struct shell *sh, size_t argc,
976976
return err;
977977
}
978978

979-
if (!IN_RANGE(segment, INT32_MIN, INT32_MAX)) {
979+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(segment, INT32_MIN, INT32_MAX)) {
980980
shell_error(sh, "Invalid segment: %ld", segment);
981981

982982
return -ENOEXEC;
@@ -1086,7 +1086,7 @@ static int cmd_media_goto_track(const struct shell *sh, size_t argc,
10861086
return err;
10871087
}
10881088

1089-
if (!IN_RANGE(track, INT32_MIN, INT32_MAX)) {
1089+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(track, INT32_MIN, INT32_MAX)) {
10901090
shell_error(sh, "Invalid track: %ld", track);
10911091

10921092
return -ENOEXEC;
@@ -1194,7 +1194,7 @@ static int cmd_media_goto_group(const struct shell *sh, size_t argc,
11941194
return err;
11951195
}
11961196

1197-
if (!IN_RANGE(group, INT32_MIN, INT32_MAX)) {
1197+
if (sizeof(long) != sizeof(int32_t) && !IN_RANGE(group, INT32_MIN, INT32_MAX)) {
11981198
shell_error(sh, "Invalid group: %ld", group);
11991199

12001200
return -ENOEXEC;

0 commit comments

Comments
 (0)