Skip to content

Commit

Permalink
Fix panic on sequence_init() when size is 0 (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscarchoi authored Jun 21, 2024
1 parent ede2291 commit 7fd9a8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rosidl_runtime_rs/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,10 @@ macro_rules! impl_sequence_alloc_for_primitive_type {
unsafe {
// This allocates space and sets seq.size and seq.capacity to size
let ret = $init_func(seq as *mut _, size);
// Zero memory, since it will be uninitialized if there is no default value
std::ptr::write_bytes(seq.data, 0u8, size);
if !seq.data.is_null() {
// Zero memory, since it will be uninitialized if there is no default value
std::ptr::write_bytes(seq.data, 0u8, size);
}
ret
}
}
Expand Down

0 comments on commit 7fd9a8b

Please sign in to comment.