Skip to content

Commit 7125ac2

Browse files
authored
Merge pull request #2691 from ra1nb0w/strict-overflow
audio_device.c: fix strict-overflow warning with gcc >= 12
2 parents 756ad35 + 8f69902 commit 7125ac2

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/class/audio/audio_device.c

+16-10
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,8 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
14901490
#endif
14911491
uint8_t const *p_desc = _audiod_fct[i].p_desc;
14921492
uint8_t const *p_desc_end = p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
1493-
while (p_desc < p_desc_end)
1493+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
1494+
while (p_desc_end - p_desc > 0)
14941495
{
14951496
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
14961497
{
@@ -1740,7 +1741,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17401741
uint8_t const *p_desc_end = audio->p_desc + audio->desc_length - TUD_AUDIO_DESC_IAD_LEN;
17411742

17421743
// p_desc starts at required interface with alternate setting zero
1743-
while (p_desc < p_desc_end)
1744+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
1745+
while (p_desc_end - p_desc > 0)
17441746
{
17451747
// Find correct interface
17461748
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const * )p_desc)->bInterfaceNumber == itf && ((tusb_desc_interface_t const * )p_desc)->bAlternateSetting == alt)
@@ -1750,7 +1752,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17501752
#endif
17511753
// From this point forward follow the EP descriptors associated to the current alternate setting interface - Open EPs if necessary
17521754
uint8_t foundEPs = 0, nEps = ((tusb_desc_interface_t const * )p_desc)->bNumEndpoints;
1753-
while (foundEPs < nEps && p_desc < p_desc_end)
1755+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
1756+
while (foundEPs < nEps && (p_desc_end - p_desc > 0))
17541757
{
17551758
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
17561759
{
@@ -2394,7 +2397,8 @@ static bool audiod_get_AS_interface_index(uint8_t itf, audiod_function_t * audio
23942397
p_desc += ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength;
23952398

23962399
uint8_t tmp = 0;
2397-
while (p_desc < p_desc_end)
2400+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
2401+
while (p_desc_end - p_desc > 0)
23982402
{
23992403
// We assume the number of alternate settings is increasing thus we return the index of alternate setting zero!
24002404
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const * )p_desc)->bAlternateSetting == 0)
@@ -2447,7 +2451,8 @@ static bool audiod_verify_entity_exists(uint8_t itf, uint8_t entityID, uint8_t *
24472451
uint8_t const *p_desc_end = ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength + p_desc;
24482452
p_desc = tu_desc_next(p_desc); // Get past CS AC descriptor
24492453

2450-
while (p_desc < p_desc_end)
2454+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
2455+
while (p_desc_end - p_desc > 0)
24512456
{
24522457
if (p_desc[3] == entityID) // Entity IDs are always at offset 3
24532458
{
@@ -2471,8 +2476,8 @@ static bool audiod_verify_itf_exists(uint8_t itf, uint8_t *func_id)
24712476
// Get pointer at beginning and end
24722477
uint8_t const *p_desc = _audiod_fct[i].p_desc;
24732478
uint8_t const *p_desc_end = _audiod_fct[i].p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
2474-
2475-
while (p_desc < p_desc_end)
2479+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
2480+
while (p_desc_end - p_desc > 0)
24762481
{
24772482
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const *)_audiod_fct[i].p_desc)->bInterfaceNumber == itf)
24782483
{
@@ -2500,7 +2505,8 @@ static bool audiod_verify_ep_exists(uint8_t ep, uint8_t *func_id)
25002505
uint8_t const *p_desc = tu_desc_next(_audiod_fct[i].p_desc);
25012506
p_desc += ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength;
25022507

2503-
while (p_desc < p_desc_end)
2508+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
2509+
while (p_desc_end - p_desc > 0)
25042510
{
25052511
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT && ((tusb_desc_endpoint_t const * )p_desc)->bEndpointAddress == ep)
25062512
{
@@ -2531,8 +2537,8 @@ static void audiod_parse_for_AS_params(audiod_function_t* audio, uint8_t const *
25312537
#endif
25322538

25332539
p_desc = tu_desc_next(p_desc); // Exclude standard AS interface descriptor of current alternate interface descriptor
2534-
2535-
while (p_desc < p_desc_end)
2540+
// Condition modified from p_desc < p_desc_end to prevent gcc>=12 strict-overflow warning
2541+
while (p_desc_end - p_desc > 0)
25362542
{
25372543
// Abort if follow up descriptor is a new standard interface descriptor - indicates the last AS descriptor was already finished
25382544
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) break;

0 commit comments

Comments
 (0)