Skip to content

Commit 199f308

Browse files
committed
Guard against incorrect read_buf_exact implementations
1 parent 65b5d76 commit 199f308

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

library/std/src/io/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,8 @@ pub trait Read {
12781278
let mut buf = [MaybeUninit::uninit(); N];
12791279
let mut borrowed_buf = BorrowedBuf::from(buf.as_mut_slice());
12801280
self.read_buf_exact(borrowed_buf.unfilled())?;
1281+
// Guard against incorrect `read_buf_exact` implementations.
1282+
assert_eq!(borrowed_buf.len(), N);
12811283
Ok(unsafe { MaybeUninit::array_assume_init(buf) })
12821284
}
12831285
}

0 commit comments

Comments
 (0)