diff --git a/tokio/src/io/util/take.rs b/tokio/src/io/util/take.rs index df2f61b9e60..ac1f2aef416 100644 --- a/tokio/src/io/util/take.rs +++ b/tokio/src/io/util/take.rs @@ -1,6 +1,7 @@ use crate::io::{AsyncBufRead, AsyncRead, ReadBuf}; use pin_project_lite::pin_project; +use std::convert::TryFrom; use std::pin::Pin; use std::task::{Context, Poll}; use std::{cmp, io}; @@ -85,7 +86,7 @@ impl AsyncRead for Take { } let me = self.project(); - let mut b = buf.take(*me.limit_ as usize); + let mut b = buf.take(usize::try_from(*me.limit_).unwrap_or(usize::MAX)); let buf_ptr = b.filled().as_ptr(); ready!(me.inner.poll_read(cx, &mut b))?;