History

fix pointer aliasing in ItemSliceSend

Same reasoning as for the fix in in_parallel.rs. Thanks to @cramertj for spotting this.

Martin von Zweigbergk committed 2 years ago

Commit 17a7c6a1 parent c684b261 file · +3 −3Browse files

Unified · Split

gix-pack/src/cache/delta/traverse/util.rs+3−3
@@ -1,6 +1,6 @@
1use crate::cache::delta::Item;1use crate::cache::delta::Item;
2 2
3pub struct ItemSliceSend<T>(*mut [T])3pub struct ItemSliceSend<T>(*mut T)
4where4where
5 T: Send;5 T: Send;
6 6
@@ -9,7 +9,7 @@ where · 2 unmodified lines
9 T: Send,9 T: Send,
10{10{
11 pub fn new(items: &mut [T]) -> Self {11 pub fn new(items: &mut [T]) -> Self {
12 ItemSliceSend(std::ptr::slice_from_raw_parts_mut(items.as_mut_ptr(), items.len()))12 ItemSliceSend(items.as_mut_ptr())
13 }13 }
14}14}
15 15
@@ -66,7 +66,7 @@ impl<'a, T: Send> Node<'a, T> { · 50 unmodified lines
66 // SAFETY: The resulting mutable pointer cannot be yielded by any other node.66 // SAFETY: The resulting mutable pointer cannot be yielded by any other node.
67 #[allow(unsafe_code)]67 #[allow(unsafe_code)]
68 Node {68 Node {
69 item: &mut unsafe { &mut *children.0 }[index as usize],69 item: unsafe { &mut *children.0.add(index as usize) },
70 child_items: children.clone(),70 child_items: children.clone(),
71 }71 }
72 })72 })