diff options
Diffstat (limited to 'tokio/tests/io_read.rs')
-rw-r--r-- | tokio/tests/io_read.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tokio/tests/io_read.rs b/tokio/tests/io_read.rs index 29d7d6d7..cb1aa705 100644 --- a/tokio/tests/io_read.rs +++ b/tokio/tests/io_read.rs @@ -36,3 +36,24 @@ async fn read() { assert_eq!(n, 11); assert_eq!(buf[..], b"hello world"[..]); } + +struct BadAsyncRead; + +impl AsyncRead for BadAsyncRead { + fn poll_read( + self: Pin<&mut Self>, + _cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> Poll<io::Result<()>> { + *buf = ReadBuf::new(Box::leak(vec![0; buf.capacity()].into_boxed_slice())); + buf.advance(buf.capacity()); + Poll::Ready(Ok(())) + } +} + +#[tokio::test] +#[should_panic] +async fn read_buf_bad_async_read() { + let mut buf = Vec::with_capacity(10); + BadAsyncRead.read_buf(&mut buf).await.unwrap(); +} |