Add a proper implementation of Clone for C API vector types
The previous implementation used a shallow copy, which is incorrect and could lead to a use-after-free.
This commit is contained in:
@@ -29,7 +29,6 @@ macro_rules! declare_vecs {
|
||||
))*
|
||||
) => {$(
|
||||
#[repr(C)]
|
||||
#[derive(Clone)]
|
||||
pub struct $name {
|
||||
size: usize,
|
||||
data: *mut $elem_ty,
|
||||
@@ -80,6 +79,12 @@ macro_rules! declare_vecs {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for $name {
|
||||
fn clone(&self) -> Self {
|
||||
self.as_slice().to_vec().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<$elem_ty>> for $name {
|
||||
fn from(vec: Vec<$elem_ty>) -> Self {
|
||||
let mut vec = vec.into_boxed_slice();
|
||||
|
||||
Reference in New Issue
Block a user