From 09d3bef0a84715d31ec08f47dd864831e949b4fb Mon Sep 17 00:00:00 2001 From: stelzo Date: Fri, 24 May 2024 16:11:32 +0200 Subject: [PATCH] fix UB in direct copy --- rpcl2/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpcl2/src/lib.rs b/rpcl2/src/lib.rs index 1b7b494..af4c01d 100644 --- a/rpcl2/src/lib.rs +++ b/rpcl2/src/lib.rs @@ -687,7 +687,7 @@ impl PointCloud2Msg { let bytes_total = vec.len() * point_step as usize; cloud.data.resize(bytes_total, u8::default()); - let raw_data: *mut C = cloud.data.as_ptr() as *mut C; + let raw_data: *mut C = cloud.data.as_mut_ptr() as *mut C; unsafe { core::ptr::copy_nonoverlapping( vec.as_ptr().cast::(), @@ -1006,10 +1006,10 @@ impl PointData { #[inline] fn from_buffer(data: &[u8], offset: usize, datatype: FieldDatatype, endian: Endian) -> Self { debug_assert!(data.len() >= offset + datatype.size()); - let bytes = [u8::default(); core::mem::size_of::()]; + let mut bytes = [u8::default(); core::mem::size_of::()]; unsafe { let data_ptr = data.as_ptr().add(offset); - let bytes_ptr = bytes.as_ptr() as *mut u8; + let bytes_ptr = bytes.as_mut_ptr() as *mut u8; core::ptr::copy_nonoverlapping(data_ptr, bytes_ptr, datatype.size()); }