Skip to content

Commit 6e389b5

Browse files
committed
Fix undefined behavior due to uninitialized bytes in Usbd::write()
Fixes #15
1 parent c615907 commit 6e389b5

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/usbd.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! * No notification when the status stage is ACK'd.
88
99
use core::cell::Cell;
10-
use core::mem::MaybeUninit;
1110
use core::sync::atomic::{compiler_fence, Ordering};
1211
use critical_section::{CriticalSection, Mutex};
1312
use usb_device::{
@@ -375,12 +374,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
375374
return Err(UsbError::WouldBlock);
376375
}
377376

378-
let mut ram_buf: MaybeUninit<[u8; 64]> = MaybeUninit::uninit();
379-
unsafe {
380-
let slice = &mut *ram_buf.as_mut_ptr();
381-
slice[..buf.len()].copy_from_slice(buf);
382-
}
383-
let ram_buf = unsafe { ram_buf.assume_init() };
377+
let mut ram_buf = [0u8; 64];
378+
ram_buf[..buf.len()].copy_from_slice(buf);
384379

385380
let epin = [
386381
&regs.epin0,

0 commit comments

Comments
 (0)