From 47a765f848bcefee298eefd099688f96b026cc62 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 24 Sep 2024 15:04:54 +0000 Subject: [PATCH] fix unsound pointer arithmetic --- src/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iter.rs b/src/iter.rs index e5dcb5c..85d9e79 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -45,7 +45,7 @@ impl<'a> Bytes<'a> { pub fn peek_ahead(&self, n: usize) -> Option { // SAFETY: obtain a potentially OOB pointer that is later compared against the `self.end` // pointer. - let ptr = unsafe { self.cursor.add(n) }; + let ptr = self.cursor.wrapping_add(n); if ptr < self.end { // SAFETY: bounds checked pointer dereference is safe Some(unsafe { *ptr })