Skip to content

Commit

Permalink
Merge pull request #200 from alufers/fix/get-unchecked-mut-panics
Browse files Browse the repository at this point in the history
Replace .get_unchecked_mut() with .as_mut_ptr().add() when accessing iso_packet_desc (fixes #199)
  • Loading branch information
a1ien authored Apr 15, 2024
2 parents 29694b9 + 4a69bca commit 03f6f53
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions libusb1-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,7 @@ pub unsafe fn libusb_fill_iso_transfer(
#[inline]
pub unsafe fn libusb_set_iso_packet_lengths(transfer: *mut libusb_transfer, length: c_uint) {
for i in 0..(*transfer).num_iso_packets {
(*transfer)
.iso_packet_desc
.get_unchecked_mut(i as usize)
.length = length;
(*(*transfer).iso_packet_desc.as_mut_ptr().add(i as usize)).length = length;
}
}

Expand All @@ -675,10 +672,7 @@ pub unsafe fn libusb_get_iso_packet_buffer(
}
let mut offset = 0;
for i in 0..packet {
offset += (*transfer)
.iso_packet_desc
.get_unchecked_mut(i as usize)
.length;
offset += (*(*transfer).iso_packet_desc.as_mut_ptr().add(i as usize)).length;
}

(*transfer).buffer.add(offset as usize)
Expand All @@ -695,5 +689,5 @@ pub unsafe fn libusb_get_iso_packet_buffer_simple(

(*transfer)
.buffer
.add(((*transfer).iso_packet_desc.get_unchecked_mut(0).length * packet) as usize)
.add(((*(*transfer).iso_packet_desc.as_mut_ptr().add(0)).length * packet) as usize)
}

0 comments on commit 03f6f53

Please sign in to comment.