Skip to content

Commit b9b306b

Browse files
HiFiPhileCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
1 parent a92aff2 commit b9b306b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/class/audio/audio_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,17 +867,17 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint
867867

868868
// Advance to next interface descriptor
869869
p_desc = tu_desc_next(p_desc);
870-
while (p_desc_end - p_desc > 0 && tu_desc_type(p_desc) != TUSB_DESC_INTERFACE) {
870+
while (tu_desc_in_bounds(p_desc, p_desc_end) && tu_desc_type(p_desc) != TUSB_DESC_INTERFACE) {
871871
p_desc = tu_desc_next(p_desc);
872872
}
873873

874874
// Verify next interface is Audio Streaming (subclass 2), not MIDI Streaming (subclass 3)
875-
if (p_desc_end - p_desc > 0) {
875+
if (p_desc_end - p_desc >= (int)sizeof(tusb_desc_interface_t)) {
876876
tusb_desc_interface_t const *next_itf = (tusb_desc_interface_t const *) p_desc;
877877
TU_VERIFY(next_itf->bInterfaceClass == TUSB_CLASS_AUDIO &&
878878
next_itf->bInterfaceSubClass == AUDIO_SUBCLASS_STREAMING, 0);
879879
} else {
880-
// No further interface found
880+
// No further interface found or not enough bytes for interface descriptor
881881
return 0;
882882
}
883883
}

0 commit comments

Comments
 (0)