Skip to content

Commit 911c05f

Browse files
committed
Demote ItemSliceMut::get_mut() bound-check to debug-code only.
By now we are certain the used indices are in bounds, but if they are not this would not be detected by the test-suite first.
1 parent ef21617 commit 911c05f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

gix-pack/src/cache/delta/traverse/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod node {
5757
/// Children are `Node`s referring to pack entries whose base object is this pack entry.
5858
pub fn into_child_iter(self) -> impl Iterator<Item = Node<'a, T>> + 'a {
5959
let children = self.child_items;
60+
// SAFETY: The index is a valid index into the children array.
6061
// SAFETY: The resulting mutable pointer cannot be yielded by any other node.
6162
#[allow(unsafe_code)]
6263
self.item.children.iter().map(move |&index| Node {

gix-pack/src/cache/delta/traverse/util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ where
55
T: Send,
66
{
77
items: *mut T,
8+
#[cfg(debug_assertions)]
89
len: usize,
910
phantom: PhantomData<&'a T>,
1011
}
@@ -16,14 +17,16 @@ where
1617
pub fn new(items: &'a mut [T]) -> Self {
1718
ItemSliceSync {
1819
items: items.as_mut_ptr(),
20+
#[cfg(debug_assertions)]
1921
len: items.len(),
2022
phantom: PhantomData,
2123
}
2224
}
2325

24-
// SAFETY: The index must not be reused concurrently
26+
// SAFETY: The index must point into the slice and must not be reused concurrently.
2527
#[allow(unsafe_code)]
2628
pub unsafe fn get_mut(&self, index: usize) -> &'a mut T {
29+
#[cfg(debug_assertions)]
2730
if index >= self.len {
2831
panic!("index out of bounds: the len is {} but the index is {index}", self.len);
2932
}

0 commit comments

Comments
 (0)