@@ -338,7 +338,7 @@ impl<T: SequenceAlloc + Clone, const N: usize> TryFrom<&[T]> for BoundedSequence
338338impl < T : SequenceAlloc , const N : usize > TryFrom < Vec < T > > for BoundedSequence < T , N > {
339339 type Error = SequenceExceedsBoundsError ;
340340 fn try_from ( v : Vec < T > ) -> Result < Self , Self :: Error > {
341- match v. len ( ) {
341+ match v. len ( ) > N {
342342 true => Err ( SequenceExceedsBoundsError {
343343 len : v. len ( ) ,
344344 upper_bound : N ,
@@ -541,7 +541,6 @@ impl std::error::Error for SequenceExceedsBoundsError {}
541541/// * `$copy_func:ident` - The name of the extern "C" function used to copy a sequence.
542542macro_rules! impl_sequence_alloc_for_primitive_type {
543543 ( $rust_type: ty, $init_func: ident, $fini_func: ident, $copy_func: ident) => {
544- /// Provides default implementations for SequenceAlloc for primitive types.
545544 #[ link( name = "rosidl_runtime_c" ) ]
546545 extern "C" {
547546 fn $init_func( seq: * mut Sequence <$rust_type>, size: usize ) -> bool ;
@@ -555,12 +554,13 @@ macro_rules! impl_sequence_alloc_for_primitive_type {
555554 impl SequenceAlloc for $rust_type {
556555 fn sequence_init( seq: & mut Sequence <Self >, size: usize ) -> bool {
557556 // SAFETY: There are no special preconditions to the sequence_init function.
557+
558558 unsafe {
559- match seq. data. is_null( ) {
560- // This allocates space and sets seq.size and seq.capacity to size
561- true => $init_func( seq as * mut _, size) ,
562- _ => std:: ptr:: write_bytes( seq. data, 0u8 , size) ;
559+ if !seq. data. is_null( ) {
560+ // Zero memory, since it will be uninitialized if there is no default value
561+ std:: ptr:: write_bytes( seq. data, 0u8 , size) ;
563562 }
563+ $init_func( seq as * mut _, size)
564564 }
565565 }
566566 fn sequence_fini( seq: & mut Sequence <Self >) {
0 commit comments