Re:Writing into Uninitialized Buffers in Rust
by ironhaven on Wednesday May 21, 2025 @01:13AM
(#44048478)
That's right. Line 3 is undefined behaviour because you are creating mutable references to the uninit spare capacity of the vec. copy_to_slice only works with writing to initialized slices. The proper way for you example to mess with the uninitialized memory on a vec would be only use raw pointers or calling the newly added Vec::spare_capacity_mut function on the vec that returns a slice of MaybeUninit
[ Parent
| on HN ]
There are no comments on this comment yet.