fix UB in direct copy
This commit is contained in:
parent
8b26fb6d72
commit
09d3bef0a8
|
|
@ -687,7 +687,7 @@ impl PointCloud2Msg {
|
||||||
|
|
||||||
let bytes_total = vec.len() * point_step as usize;
|
let bytes_total = vec.len() * point_step as usize;
|
||||||
cloud.data.resize(bytes_total, u8::default());
|
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 {
|
unsafe {
|
||||||
core::ptr::copy_nonoverlapping(
|
core::ptr::copy_nonoverlapping(
|
||||||
vec.as_ptr().cast::<u8>(),
|
vec.as_ptr().cast::<u8>(),
|
||||||
|
|
@ -1006,10 +1006,10 @@ impl PointData {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_buffer(data: &[u8], offset: usize, datatype: FieldDatatype, endian: Endian) -> Self {
|
fn from_buffer(data: &[u8], offset: usize, datatype: FieldDatatype, endian: Endian) -> Self {
|
||||||
debug_assert!(data.len() >= offset + datatype.size());
|
debug_assert!(data.len() >= offset + datatype.size());
|
||||||
let bytes = [u8::default(); core::mem::size_of::<f64>()];
|
let mut bytes = [u8::default(); core::mem::size_of::<f64>()];
|
||||||
unsafe {
|
unsafe {
|
||||||
let data_ptr = data.as_ptr().add(offset);
|
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());
|
core::ptr::copy_nonoverlapping(data_ptr, bytes_ptr, datatype.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue