Skip to content

Commit

Permalink
Keep the set-len refactor but use safe resize
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic authored and daniel-abramov committed Dec 19, 2024
1 parent f05398b commit b7a7817
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/protocol/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,7 @@ impl FrameCodec {
fn read_in(&mut self, stream: &mut impl Read) -> io::Result<usize> {
let len = self.in_buffer.len();
debug_assert!(self.in_buffer.capacity() > len);
// SAFETY: truncated after read so uninit bytes are never read
unsafe {
self.in_buffer.set_len(self.in_buffer.capacity());
}
self.in_buffer.resize(self.in_buffer.capacity(), 0);
let size = stream.read(&mut self.in_buffer[len..]);
self.in_buffer.truncate(len + size.as_ref().copied().unwrap_or(0));
size
Expand Down

0 comments on commit b7a7817

Please sign in to comment.