Skip to content

Commit b119671

Browse files
committed
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.
1 parent 60493b8 commit b119671

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/std/src/io/buffered/bufreader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ impl<R: Read + ?Sized> BufReader<R> {
118118
/// #![feature(bufreader_peek)]
119119
/// use std::io::{Read, BufReader};
120120
///
121-
/// let mut bytes = &b"oh, hello"[..];
121+
/// let mut bytes = &b"oh, hello there"[..];
122122
/// let mut rdr = BufReader::with_capacity(6, &mut bytes);
123123
/// assert_eq!(rdr.peek(2).unwrap(), b"oh");
124124
/// let mut buf = [0; 4];
125125
/// rdr.read(&mut buf[..]).unwrap();
126126
/// assert_eq!(&buf, b"oh, ");
127-
/// assert_eq!(rdr.peek(2).unwrap(), b"he");
127+
/// assert_eq!(rdr.peek(5).unwrap(), b"hello");
128128
/// let mut s = String::new();
129129
/// rdr.read_to_string(&mut s).unwrap();
130-
/// assert_eq!(&s, "hello");
130+
/// assert_eq!(&s, "hello there");
131131
/// assert_eq!(rdr.peek(1).unwrap().len(), 0);
132132
/// ```
133133
#[unstable(feature = "bufreader_peek", issue = "128405")]

0 commit comments

Comments
 (0)