nrf-usbd icon indicating copy to clipboard operation
nrf-usbd copied to clipboard

Possible undefined behavior in <Usbd as UsbBus>::write()

Open ia0 opened this issue 2 years ago • 0 comments
trafficstars

https://github.com/nrf-rs/nrf-usbd/blob/cbd7ed7508ab0feecbc939e6fa55976fbdf95c6a/src/usbd.rs#L378-L383

Line 380 looks like UB because we're creating a mutable reference to unitialized memory. Some write method (from MaybeUninit or the raw pointer type) should be used.

Line 383 also looks like UB because we did not initialize the whole array.

Probably the simpler solution is to use a regular array and avoid usage of unsafe.

ia0 avatar Jul 18 '23 13:07 ia0