about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorWill Woods <w@wizard.zone>2025-02-28 17:30:53 -0800
committerWill Woods <w@wizard.zone>2025-02-28 17:30:53 -0800
commitb1196717fcba13d8ff73ec06c3d8c5bee3b74ec9 (patch)
treec49815b34416472ea9aff2a2c99731ce92244d16 /library/std/src
parent60493b8973ac5ba632952eaa2f212b56bb97ccfe (diff)
downloadrust-b1196717fcba13d8ff73ec06c3d8c5bee3b74ec9.tar.gz
rust-b1196717fcba13d8ff73ec06c3d8c5bee3b74ec9.zip
Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()
This patch makes BufReader::peek()'s doctest call read_more() to refill
the buffer before the inner reader hits EOF. This exposes a bug in
read_more() that causes an out-of-bounds slice access and segfault.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/io/buffered/bufreader.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs
index 8b46738ab8a..697fb5974a3 100644
--- a/library/std/src/io/buffered/bufreader.rs
+++ b/library/std/src/io/buffered/bufreader.rs
@@ -118,16 +118,16 @@ impl<R: Read + ?Sized> BufReader<R> {
     /// #![feature(bufreader_peek)]
     /// use std::io::{Read, BufReader};
     ///
-    /// let mut bytes = &b"oh, hello"[..];
+    /// let mut bytes = &b"oh, hello there"[..];
     /// let mut rdr = BufReader::with_capacity(6, &mut bytes);
     /// assert_eq!(rdr.peek(2).unwrap(), b"oh");
     /// let mut buf = [0; 4];
     /// rdr.read(&mut buf[..]).unwrap();
     /// assert_eq!(&buf, b"oh, ");
-    /// assert_eq!(rdr.peek(2).unwrap(), b"he");
+    /// assert_eq!(rdr.peek(5).unwrap(), b"hello");
     /// let mut s = String::new();
     /// rdr.read_to_string(&mut s).unwrap();
-    /// assert_eq!(&s, "hello");
+    /// assert_eq!(&s, "hello there");
     /// assert_eq!(rdr.peek(1).unwrap().len(), 0);
     /// ```
     #[unstable(feature = "bufreader_peek", issue = "128405")]