Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertions to rcl wrapper #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion r2r/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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);
Expand Down
4 changes: 2 additions & 2 deletions r2r_rcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()); }
}
}

Expand All @@ -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
Expand Down