Skip to content

BufferedReader's fill() doesn't fill the buffer #11372

Closed
@Florob

Description

@Florob

The fill() method of BufferedReader does not fill the internal buffer, unless the buffer is completely empty. This does not match the description in the Buffer trait. One case where this can cause problems is when using read_char(), e.g.:

fn main() {
    let mut s = "a".repeat(64*1024-1);
    s.push_char('ß');

    let rdr = std::io::mem::MemReader::new(s.into_bytes());
    let mut rdr = std::io::buffered::BufferedReader::new(rdr);

    rdr.fill();
    rdr.consume(64*1024-2);

    println!("{}", rdr.read_char()); // Some('a')
    println!("{}", rdr.read_char()); // None, should be Some('ß')
    println!("{}", rdr.read_char()); // None
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions