diff --git a/src/usb_hid.rs b/src/usb_hid.rs index d2e8278..2779113 100644 --- a/src/usb_hid.rs +++ b/src/usb_hid.rs @@ -128,6 +128,10 @@ fn write_raw(device: &HidDevice, data: &[u8]) -> Result<()> { fn prepend_byte_and_offset(data: &[u8], offset: usize) -> [u8; 65] { let mut result: [u8; 65] = [0u8; 65]; result[1] = 0x0; - result[1..].copy_from_slice(&data[offset..offset + 64]); + if data.len() - offset < 64 { + result[1..].copy_from_slice(&data[offset..]); + } else { + result[1..].copy_from_slice(&data[offset..offset + 64]); + } result }