diff options
| author | Maxime Vincent <[email protected]> | 2024-08-29 17:32:43 +0200 |
|---|---|---|
| committer | Maxime Vincent <[email protected]> | 2024-08-29 17:32:43 +0200 |
| commit | abcb39a58b63c32e91b748d4380f4f6492fd28cb (patch) | |
| tree | 5f1ccc6eec18221ecd36711bd9adc5a2cd2753e7 /embassy-usb | |
| parent | f0a86070512ad739641cee7d9fa39d63f5c8a9f6 (diff) | |
Allow bos_descriptor_buf to be a zero-length slice
Diffstat (limited to 'embassy-usb')
| -rw-r--r-- | embassy-usb/src/descriptor.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index f1773fa8a..c4d79e39f 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs | |||
| @@ -308,6 +308,9 @@ impl<'a> BosWriter<'a> { | |||
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | pub(crate) fn bos(&mut self) { | 310 | pub(crate) fn bos(&mut self) { |
| 311 | if (self.writer.buf.len() - self.writer.position) < 5 { | ||
| 312 | return; | ||
| 313 | } | ||
| 311 | self.num_caps_mark = Some(self.writer.position + 4); | 314 | self.num_caps_mark = Some(self.writer.position + 4); |
| 312 | self.writer.write( | 315 | self.writer.write( |
| 313 | descriptor_type::BOS, | 316 | descriptor_type::BOS, |
| @@ -350,6 +353,9 @@ impl<'a> BosWriter<'a> { | |||
| 350 | } | 353 | } |
| 351 | 354 | ||
| 352 | pub(crate) fn end_bos(&mut self) { | 355 | pub(crate) fn end_bos(&mut self) { |
| 356 | if self.writer.position == 0 { | ||
| 357 | return; | ||
| 358 | } | ||
| 353 | self.num_caps_mark = None; | 359 | self.num_caps_mark = None; |
| 354 | let position = self.writer.position as u16; | 360 | let position = self.writer.position as u16; |
| 355 | self.writer.buf[2..4].copy_from_slice(&position.to_le_bytes()); | 361 | self.writer.buf[2..4].copy_from_slice(&position.to_le_bytes()); |
