diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-09-10 21:31:13 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-10 21:31:13 +0000 |
| commit | e535676fa29bd5922b27b005c827bd03b43f6da0 (patch) | |
| tree | 616a294d7e3f14aee2bc5dd46893cbcab18929a3 | |
| parent | 1058afd5fd32d606cd21c3010cbb93ea68f12c0c (diff) | |
| parent | abcb39a58b63c32e91b748d4380f4f6492fd28cb (diff) | |
Merge pull request #3296 from maximevince/embassy-usb-empty-bos-desc
Allow bos_descriptor_buf to be a zero-length slice
| -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()); |
