Allow bos_descriptor_buf to be a zero-length slice

This commit is contained in:
Maxime Vincent 2024-08-29 17:32:43 +02:00
parent f0a8607051
commit abcb39a58b
No known key found for this signature in database
GPG Key ID: B5A70D71BAF4CC04

View File

@ -308,6 +308,9 @@ impl<'a> BosWriter<'a> {
}
pub(crate) fn bos(&mut self) {
if (self.writer.buf.len() - self.writer.position) < 5 {
return;
}
self.num_caps_mark = Some(self.writer.position + 4);
self.writer.write(
descriptor_type::BOS,
@ -350,6 +353,9 @@ impl<'a> BosWriter<'a> {
}
pub(crate) fn end_bos(&mut self) {
if self.writer.position == 0 {
return;
}
self.num_caps_mark = None;
let position = self.writer.position as u16;
self.writer.buf[2..4].copy_from_slice(&position.to_le_bytes());