diff --git a/src/net/mod.rs b/src/net/mod.rs index f4625d3ff..45c744e5a 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -100,6 +100,7 @@ impl Bytes for [MaybeUninit] { } } +/* TODO: this implementation is unsound, see issue #308. impl Bytes for [u8] { fn as_bytes(&mut self) -> &mut [MaybeUninit] { // Safety: `MaybeUninit` is guaranteed to have the same layout as @@ -111,6 +112,7 @@ impl Bytes for [u8] { // Can't update the length of a slice. } } +*/ impl Bytes for [MaybeUninit; N] { fn as_bytes(&mut self) -> &mut [MaybeUninit] { @@ -122,6 +124,7 @@ impl Bytes for [MaybeUninit; N] { } } +/* TODO: this implementation is unsound, see issue #308. impl Bytes for [u8; N] { fn as_bytes(&mut self) -> &mut [MaybeUninit] { self.as_mut_slice().as_bytes() @@ -131,6 +134,7 @@ impl Bytes for [u8; N] { // Can't update the length of an array. } } +*/ /// The implementation for `Vec` only uses the uninitialised capacity of the /// vector. In other words the bytes currently in the vector remain untouched. diff --git a/src/net/udp.rs b/src/net/udp.rs index 4eb0d5f1d..19a7475f6 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -92,8 +92,9 @@ pub enum Connected {} /// // echos the message to standard out. /// async fn echo_server(mut ctx: actor::Context, local: SocketAddr) -> io::Result<()> { /// let mut socket = UdpSocket::bind(&mut ctx, local)?; -/// let mut buf = [0; 4096]; +/// let mut buf = Vec::with_capacity(4096); /// loop { +/// buf.clear(); /// let mut receive_msg = ctx.receive_next().fuse(); /// let mut read = socket.recv_from(&mut buf).fuse(); /// let (n, address) = select! { diff --git a/tests/functional/bytes.rs b/tests/functional/bytes.rs index 5b5b743b6..632f548ba 100644 --- a/tests/functional/bytes.rs +++ b/tests/functional/bytes.rs @@ -25,6 +25,7 @@ where len } +/* TODO: this implementation is unsound, see issue #308. #[test] fn impl_for_slice() { let mut buf = vec![0; DATA.len() * 2].into_boxed_slice(); @@ -32,6 +33,7 @@ fn impl_for_slice() { assert_eq!(n, DATA.len()); assert_eq!(&buf[..n], DATA); } +*/ #[test] fn impl_for_maybe_uninit_slice() { @@ -44,6 +46,7 @@ fn impl_for_maybe_uninit_slice() { ); } +/* TODO: this implementation is unsound, see issue #308. #[test] fn impl_for_array() { let mut buf = [0; DATA.len() * 2]; @@ -51,6 +54,7 @@ fn impl_for_array() { assert_eq!(n, DATA.len()); assert_eq!(&buf[..n], DATA); } +*/ #[test] fn impl_for_maybe_uninit_array() { diff --git a/tests/functional/udp.rs b/tests/functional/udp.rs index 73607b63a..4c8bb0ae7 100644 --- a/tests/functional/udp.rs +++ b/tests/functional/udp.rs @@ -95,12 +95,13 @@ async fn unconnected_udp_actor( let bytes_written = socket.send_to(&DATA, peer_address).await?; assert_eq!(bytes_written, DATA.len()); - let mut buf = [0; DATA.len() + 2]; + let mut buf = Vec::with_capacity(DATA.len() + 2); let (bytes_peeked, address) = socket.peek_from(&mut buf).await?; assert_eq!(bytes_peeked, DATA.len()); assert_eq!(&buf[..bytes_peeked], &*DATA); assert_eq!(address, peer_address); + buf.clear(); let (bytes_read, address) = socket.recv_from(&mut buf).await?; assert_eq!(bytes_read, DATA.len()); assert_eq!(&buf[..bytes_read], &*DATA); @@ -122,11 +123,12 @@ async fn connected_udp_actor( let bytes_written = socket.send(&DATA).await?; assert_eq!(bytes_written, DATA.len()); - let mut buf = [0; DATA.len() + 2]; + let mut buf = Vec::with_capacity(DATA.len() + 2); let bytes_peeked = socket.peek(&mut buf).await?; assert_eq!(bytes_peeked, DATA.len()); assert_eq!(&buf[..bytes_peeked], &*DATA); + buf.clear(); let bytes_read = socket.recv(&mut buf).await?; assert_eq!(bytes_read, DATA.len()); assert_eq!(&buf[..bytes_read], &*DATA);