From 0053553d0b091220b70e543bd3f93b5df5df81cc Mon Sep 17 00:00:00 2001 From: zoumi Date: Thu, 12 Dec 2019 19:56:47 +0800 Subject: [PATCH] prevent panic when call read_control() --- src/device_handle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device_handle.rs b/src/device_handle.rs index eb9c360..555b59a 100644 --- a/src/device_handle.rs +++ b/src/device_handle.rs @@ -401,7 +401,7 @@ impl<'a> DeviceHandle<'a> { /// This function returns a list of languages that can be used to read the device's string /// descriptors. pub fn read_languages(&self, timeout: Duration) -> ::Result> { - let mut buf = Vec::::with_capacity(256); + let mut buf = Vec::::with_capacity(255); let mut buf_slice = unsafe { slice::from_raw_parts_mut((&mut buf[..]).as_mut_ptr(), buf.capacity()) @@ -428,7 +428,7 @@ impl<'a> DeviceHandle<'a> { /// /// `language` should be one of the languages returned from [`read_languages`](#method.read_languages). pub fn read_string_descriptor(&self, language: Language, index: u8, timeout: Duration) -> ::Result { - let mut buf = Vec::::with_capacity(256); + let mut buf = Vec::::with_capacity(255); let mut buf_slice = unsafe { slice::from_raw_parts_mut((&mut buf[..]).as_mut_ptr(), buf.capacity())