Skip to content

Commit

Permalink
Fix UB in impl VertexBufferCollection for Vec<Subbuffer<T>>
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Oct 16, 2024
1 parent 1da590f commit 2504863
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vulkano/src/pipeline/graphics/vertex_input/collection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::buffer::Subbuffer;
use std::mem;
use std::mem::{self, ManuallyDrop};

/// A collection of vertex buffers.
pub trait VertexBuffersCollection {
Expand Down Expand Up @@ -32,8 +32,13 @@ impl<T: ?Sized> VertexBuffersCollection for Vec<Subbuffer<T>> {
mem::align_of::<Subbuffer<[u8]>>(),
);

let mut this = ManuallyDrop::new(self);
let cap = this.capacity();
let len = this.len();
let ptr = this.as_mut_ptr();

// SAFETY: All `Subbuffer`s share the same layout.
unsafe { mem::transmute::<Vec<Subbuffer<T>>, Vec<Subbuffer<[u8]>>>(self) }
unsafe { Vec::from_raw_parts(ptr.cast(), len, cap) }
}
}

Expand Down

0 comments on commit 2504863

Please sign in to comment.