diff options
| author | Jomer.Dev <[email protected]> | 2024-01-29 17:14:23 +0100 |
|---|---|---|
| committer | Jomer.Dev <[email protected]> | 2024-01-29 17:14:23 +0100 |
| commit | 0708ce1410404ebf66c94fadc71cb7b0128161d3 (patch) | |
| tree | 5f33febbaffecddb9d7bf1815b562ffff496a3cb | |
| parent | 681393150dcb9704e55bcb315cb7793e0f56607e (diff) | |
Use saturating_sub to make sure we don't overflow
| -rw-r--r-- | embassy-rp/src/uart/mod.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 9f5ba4e8a..f372cb640 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs | |||
| @@ -604,8 +604,8 @@ impl<'d, T: Instance> UartRx<'d, T, Async> { | |||
| 604 | return match (all_full, last_was_break) { | 604 | return match (all_full, last_was_break) { |
| 605 | (true, true) | (false, _) => { | 605 | (true, true) | (false, _) => { |
| 606 | // We got less than the full amount + a break, or the full amount | 606 | // We got less than the full amount + a break, or the full amount |
| 607 | // and the last byte was a break. Subtract the break off. | 607 | // and the last byte was a break. Subtract the break off by adding one to sval. |
| 608 | Ok((next_addr - 1) - sval) | 608 | Ok(next_addr.saturating_sub(1 + sval)) |
| 609 | } | 609 | } |
| 610 | (true, false) => { | 610 | (true, false) => { |
| 611 | // We finished the whole DMA, and the last DMA'd byte was NOT a break | 611 | // We finished the whole DMA, and the last DMA'd byte was NOT a break |
