From c56961e0b1cd5669bc1d3f0210782a21556a0a1c Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Tue, 8 Oct 2024 13:03:52 +0000 Subject: [PATCH 1/2] Add additional assertions to rcl wrapper --- r2r/src/nodes.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/r2r/src/nodes.rs b/r2r/src/nodes.rs index 7610535fd..3ff8aa05a 100644 --- a/r2r/src/nodes.rs +++ b/r2r/src/nodes.rs @@ -1239,12 +1239,17 @@ impl Node { let types = unsafe { std::slice::from_raw_parts(tnat.types, tnat.names.size) }; for (n, t) in names.iter().zip(types) { + assert!(!(*n).is_null()); let topic_name = unsafe { CStr::from_ptr(*n).to_str().unwrap().to_owned() }; + assert!(!t.data.is_null()); let topic_types = unsafe { std::slice::from_raw_parts(t, t.size) }; let topic_types: Vec = unsafe { topic_types .iter() - .map(|t| CStr::from_ptr(*(t.data)).to_str().unwrap().to_owned()) + .map(|t| { + assert!(*(t.data) != std::ptr::null_mut()); + CStr::from_ptr(*(t.data)).to_str().unwrap().to_owned() + }) .collect() }; res.insert(topic_name, topic_types); From d2aa68928163fb6c091b9c5b5cc519f2869368a0 Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Wed, 9 Oct 2024 07:47:02 +0000 Subject: [PATCH 2/2] Use copy_nonoverlapping for more efficient sequence filling --- r2r_rcl/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/r2r_rcl/src/lib.rs b/r2r_rcl/src/lib.rs index 54eb13567..efb189ed3 100644 --- a/r2r_rcl/src/lib.rs +++ b/r2r_rcl/src/lib.rs @@ -116,7 +116,7 @@ macro_rules! primitive_sequence { unsafe { [<$ctype __Sequence__fini>] (self as *mut _); } unsafe { [<$ctype __Sequence__init>] (self as *mut _, values.len()); } if self.data != std::ptr::null_mut() { - unsafe { std::ptr::copy(values.as_ptr(), self.data, values.len()); } + unsafe { std::ptr::copy_nonoverlapping(values.as_ptr(), self.data, values.len()); } } } @@ -126,7 +126,7 @@ macro_rules! primitive_sequence { } let mut target = Vec::with_capacity(self.size); unsafe { - std::ptr::copy(self.data, target.as_mut_ptr(), self.size); + std::ptr::copy_nonoverlapping(self.data, target.as_mut_ptr(), self.size); target.set_len(self.size); } target