aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-10-08 09:27:48 -0400
committerBrian Cully <bjc@kublai.com>2019-10-08 09:27:48 -0400
commit6d6fd2617ab909987e5ddecfb36519f0667ecf57 (patch)
tree67ad93f566845bfbfd661f0bca36081845ec410a
parente0542778e674d623b48ed0de9ab4195d2f1bfc5e (diff)
downloadatsamd-usb-host-6d6fd2617ab909987e5ddecfb36519f0667ecf57.tar.gz
atsamd-usb-host-6d6fd2617ab909987e5ddecfb36519f0667ecf57.zip
Don't `assume_init` when allocating device descriptor buffer.
Unwrap after `assert` of transfer length.
-rw-r--r--src/lib.rs8
1 files changed, 5 insertions, 3 deletions
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::<DeviceDescriptor>::uninit().assume_init() };
- self.control_transfer(
+
+ let mut dev_desc: MaybeUninit<DeviceDescriptor> = 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::<DeviceDescriptor>());
+ let dev_desc = unsafe { dev_desc.assume_init() };
trace!(" -- dev_desc: {:?}", dev_desc);