From 91fe6f9343a384dd7d598705a4bc4b137845dbea Mon Sep 17 00:00:00 2001 From: joboet Date: Thu, 11 Apr 2024 18:33:46 +0200 Subject: core: panic on overflow in `BorrowedCursor` --- library/std/src/io/tests.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'library/std/src') diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs index eb5d5988768..090a091b09a 100644 --- a/library/std/src/io/tests.rs +++ b/library/std/src/io/tests.rs @@ -209,6 +209,15 @@ fn read_buf_exact() { assert_eq!(c.read_buf_exact(buf.unfilled()).unwrap_err().kind(), io::ErrorKind::UnexpectedEof); } +#[test] +#[should_panic] +fn borrowed_cursor_advance_overflow() { + let mut buf = [0; 512]; + let mut buf = BorrowedBuf::from(&mut buf[..]); + buf.unfilled().advance(1); + buf.unfilled().advance(usize::MAX); +} + #[test] fn take_eof() { struct R; -- cgit 1.4.1-3-g733a5