We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 8384b56 + 84f9d7b commit 242ff95Copy full SHA for 242ff95
std/src/io/mod.rs
@@ -2989,11 +2989,11 @@ impl<T: Read> Read for Take<T> {
2989
return Ok(());
2990
}
2991
2992
- if self.limit <= buf.capacity() as u64 {
2993
- // if we just use an as cast to convert, limit may wrap around on a 32 bit target
2994
- let limit = cmp::min(self.limit, usize::MAX as u64) as usize;
+ if self.limit < buf.capacity() as u64 {
+ // The condition above guarantees that `self.limit` fits in `usize`.
+ let limit = self.limit as usize;
2995
2996
- let extra_init = cmp::min(limit as usize, buf.init_ref().len());
+ let extra_init = cmp::min(limit, buf.init_ref().len());
2997
2998
// SAFETY: no uninit data is written to ibuf
2999
let ibuf = unsafe { &mut buf.as_mut()[..limit] };
0 commit comments