Switch BufMut::bytes_mut to&mut UninitSlice (#433)

The way BufMut uses MaybeUninit can lead to unsoundness. This replaces
MaybeUnit with a type owned by bytes so we can ensure the usage patterns
are sound.

Refs: #328
This commit is contained in:
Carl Lerche
2020-10-19 15:48:23 -07:00
committed by GitHub
parent 5a11c783ec
commit e0d8413d53
8 changed files with 241 additions and 47 deletions
+2 -4
View File
@@ -1,8 +1,6 @@
use crate::buf::IntoIter;
use crate::buf::{IntoIter, UninitSlice};
use crate::{Buf, BufMut};
use core::mem::MaybeUninit;
#[cfg(feature = "std")]
use std::io::IoSlice;
@@ -183,7 +181,7 @@ where
self.a.remaining_mut() + self.b.remaining_mut()
}
fn bytes_mut(&mut self) -> &mut [MaybeUninit<u8>] {
fn bytes_mut(&mut self) -> &mut UninitSlice {
if self.a.has_remaining_mut() {
self.a.bytes_mut()
} else {