Skip to content

Commit

Permalink
Fix assembling mutable slice from const reference
Browse files Browse the repository at this point in the history
The pointer to `slice::from_raw_parts_mut` must have provenance for
accessing the underlying elements mutably. A pointer acquired by
slice::as_ptr does not have that, it only allows shared read access.

That's mostly a theoretical concern of the pointer tagging model
proposed by RustBelt.
  • Loading branch information
HeroicKatora committed Nov 12, 2020
1 parent 1ec76c9 commit 0053e5d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/color.rs
Expand Up @@ -253,7 +253,7 @@ impl<T: Primitive + 'static> Pixel for $ident<T> {
}
fn from_slice_mut(slice: &mut [T]) -> &mut $ident<T> {
assert_eq!(slice.len(), $channels);
unsafe { &mut *(slice.as_ptr() as *mut $ident<T>) }
unsafe { &mut *(slice.as_mut_ptr() as *mut $ident<T>) }
}

fn to_rgb(&self) -> Rgb<T> {
Expand Down

0 comments on commit 0053e5d

Please sign in to comment.