Skip to content

Commit

Permalink
Merge pull request #195 from alufers/fix/iterating-over-zero-endpoint…
Browse files Browse the repository at this point in the history
…-descriptors

fix: panic when trying to iterate over an interface with zero endpoints
  • Loading branch information
a1ien authored Mar 5, 2024
2 parents 15c2910 + 5e8e36e commit aa11ec9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/interface_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ impl<'a> InterfaceDescriptor<'a> {

/// Returns an iterator over the interface's endpoint descriptors.
pub fn endpoint_descriptors(&self) -> EndpointDescriptors<'a> {
let endpoints = unsafe {
slice::from_raw_parts(
self.descriptor.endpoint,
self.descriptor.bNumEndpoints as usize,
)
let endpoints = match self.descriptor.bNumEndpoints {
0 => &[],
n => unsafe { slice::from_raw_parts(self.descriptor.endpoint, n as usize) },
};

EndpointDescriptors {
Expand Down

0 comments on commit aa11ec9

Please sign in to comment.