diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 9fe985aab..26d84fc33 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Feature `wifi-logs` doesn't break the build anymore (#2117) +- Fixed a panic when overflow-checks are enabled (#2164) ### Removed diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 8ad1df73c..110c5f4fd 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -63,7 +63,7 @@ impl RawQueue { } fn enqueue(&mut self, item: *mut c_void) -> i32 { - if (self.current_write - self.current_read) % self.count < self.count { + if self.count() < self.count { unsafe { let p = self.storage.byte_add(self.item_size * self.current_write); p.copy_from(item as *mut u8, self.item_size); @@ -77,7 +77,7 @@ impl RawQueue { } fn try_dequeue(&mut self, item: *mut c_void) -> bool { - if (self.current_write - self.current_read) % self.count > 0 { + if self.count() > 0 { unsafe { let p = self.storage.byte_add(self.item_size * self.current_read) as *const c_void; item.copy_from(p, self.item_size); @@ -90,7 +90,11 @@ impl RawQueue { } fn count(&self) -> usize { - (self.current_write - self.current_read) % self.count + if self.current_write >= self.current_read { + self.current_write - self.current_read + } else { + self.count - self.current_read + self.current_write + } } }