Skip to content

Commit 2b215e8

Browse files
Oscarchoiesteve
authored andcommitted
Fix panic on sequence_init() when size is 0 (#407)
1 parent 9fdedc4 commit 2b215e8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rosidl_runtime_rs/src/sequence.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,10 @@ macro_rules! impl_sequence_alloc_for_primitive_type {
510510
unsafe {
511511
// This allocates space and sets seq.size and seq.capacity to size
512512
let ret = $init_func(seq as *mut _, size);
513-
// Zero memory, since it will be uninitialized if there is no default value
514-
std::ptr::write_bytes(seq.data, 0u8, size);
513+
if !seq.data.is_null() {
514+
// Zero memory, since it will be uninitialized if there is no default value
515+
std::ptr::write_bytes(seq.data, 0u8, size);
516+
}
515517
ret
516518
}
517519
}

0 commit comments

Comments
 (0)