From 914f1f9a4217456d512bb0022fcf663909afed69 Mon Sep 17 00:00:00 2001 From: RedCommander735 <40245965+RedCommander735@users.noreply.github.com> Date: Sun, 27 Jul 2025 04:45:38 +0200 Subject: [PATCH] fix: handle data not padded to 64 in helper function --- src/usb_hid.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 }