From 0708ce1410404ebf66c94fadc71cb7b0128161d3 Mon Sep 17 00:00:00 2001 From: "Jomer.Dev" Date: Mon, 29 Jan 2024 17:14:23 +0100 Subject: [PATCH] Use saturating_sub to make sure we don't overflow --- embassy-rp/src/uart/mod.rs | 4 ++-- 1 file 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> { return match (all_full, last_was_break) { (true, true) | (false, _) => { // We got less than the full amount + a break, or the full amount - // and the last byte was a break. Subtract the break off. - Ok((next_addr - 1) - sval) + // and the last byte was a break. Subtract the break off by adding one to sval. + Ok(next_addr.saturating_sub(1 + sval)) } (true, false) => { // We finished the whole DMA, and the last DMA'd byte was NOT a break