Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_buf uses in std #125404

Merged
merged 5 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix io::BufReader uses of read_buf
  • Loading branch information
a1phyr committed Sep 23, 2024
commit 04710e27d260b82865b3d4949e2e84b59c35ed66
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<R: ?Sized + Read> Read for BufReader<R> {
let prev = cursor.written();

let mut rem = self.fill_buf()?;
rem.read_buf(cursor.reborrow())?;
rem.read_buf(cursor.reborrow())?; // actually never fails

self.consume(cursor.written() - prev); //slice impl of read_buf known to never unfill buf

Expand Down
4 changes: 3 additions & 1 deletion library/std/src/io/buffered/bufreader/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ impl Buffer {
buf.set_init(self.initialized);
}

reader.read_buf(buf.unfilled())?;
let result = reader.read_buf(buf.unfilled());

self.pos = 0;
self.filled = buf.len();
self.initialized = buf.init_len();

result?;
}
Ok(self.buffer())
}
Expand Down