Skip to content

Commit

Permalink
Advance pos_of_buffer_start when writing directly to a writer
Browse files Browse the repository at this point in the history
If a message is bigger than the buffer, it will be written
directly to the writer, and there was a bug in that case where
pos_of_buffer_start was not advanced. This causes later
assertions to fail, such as the one in
Message::write_length_delimited_to, which asserts based on
total_bytes_written(), which is in turn based on
pos_of_buffer_start.
  • Loading branch information
Colecf committed May 4, 2024
1 parent 16c9dc5 commit 7bb9586
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions protobuf/src/coded_output_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl<'a> CodedOutputStream<'a> {
}
OutputTarget::Write(ref mut write, _) => {
write.write_all(bytes)?;
self.pos_of_buffer_start += bytes.len() as u64;
}
OutputTarget::Vec(ref mut vec) => {
assert!(self.buffer.pos_within_buf() == 0);
Expand Down

0 comments on commit 7bb9586

Please sign in to comment.