From 6d6fd2617ab909987e5ddecfb36519f0667ecf57 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 8 Oct 2019 09:27:48 -0400 Subject: Don't `assume_init` when allocating device descriptor buffer. Unwrap after `assert` of transfer length. --- src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 982b7a2..69b3fd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -407,9 +407,9 @@ where in_toggle: true, out_toggle: true, }; - let mut dev_desc: DeviceDescriptor = - unsafe { MaybeUninit::::uninit().assume_init() }; - self.control_transfer( + + let mut dev_desc: MaybeUninit = MaybeUninit::uninit(); + let len = self.control_transfer( &mut a0ep0, RequestType::from(( RequestDirection::DeviceToHost, @@ -421,6 +421,8 @@ where 0, Some(unsafe { to_slice_mut(&mut dev_desc) }), )?; + assert!(len == mem::size_of::()); + let dev_desc = unsafe { dev_desc.assume_init() }; trace!(" -- dev_desc: {:?}", dev_desc); -- cgit v1.2.3