@@ -63,12 +63,16 @@ macro_rules! array_setter {
6363 #[ no_mangle]
6464 pub extern "C" fn $c_setter( node: * mut node, length: usize , values: * const $ffi_type) {
6565 let node = mut_from_ptr( node) ;
66- let values = unsafe {
67- slice:: from_raw_parts( values, length)
68- . iter( )
69- . cloned( )
70- . map( From :: from)
71- . collect:: <Vec <$rust_type>>( )
66+ let values = if length == 0 {
67+ Vec :: new( )
68+ } else {
69+ unsafe {
70+ slice:: from_raw_parts( values, length)
71+ . iter( )
72+ . cloned( )
73+ . map( From :: from)
74+ . collect:: <Vec <$rust_type>>( )
75+ }
7276 } ;
7377 node. $setter( values) ;
7478 }
@@ -157,8 +161,13 @@ macro_rules! slice_struct {
157161 }
158162 impl From <$struct_name> for Vec <$rust_type> {
159163 fn from( values: $struct_name) -> Self {
160- unsafe {
161- slice:: from_raw_parts( values. values as * mut $rust_type, values. length) . to_vec( )
164+ if values. length == 0 {
165+ Vec :: new( )
166+ } else {
167+ unsafe {
168+ slice:: from_raw_parts( values. values as * mut $rust_type, values. length)
169+ . to_vec( )
170+ }
162171 }
163172 }
164173 }
@@ -795,19 +804,24 @@ impl node {
795804 BoxCastPtr :: to_mut_ptr ( node. custom_actions ( ) . into ( ) )
796805 }
797806
798- /// Caller is responsible for freeing each `custom_action` in the array.
807+ /// Caller is responsible for freeing each `custom_action` in the array
808+ /// as well as the `values` array itself.
799809 #[ no_mangle]
800810 pub extern "C" fn accesskit_node_set_custom_actions (
801811 node : * mut node ,
802812 length : usize ,
803813 values : * const * mut custom_action ,
804814 ) {
805815 let node = mut_from_ptr ( node) ;
806- let values = unsafe {
807- slice:: from_raw_parts ( values, length)
808- . iter ( )
809- . map ( |ptr| ref_from_ptr ( * ptr) . clone ( ) )
810- . collect :: < Vec < CustomAction > > ( )
816+ let values = if length == 0 {
817+ Vec :: new ( )
818+ } else {
819+ unsafe {
820+ slice:: from_raw_parts ( values, length)
821+ . iter ( )
822+ . map ( |ptr| ref_from_ptr ( * ptr) . clone ( ) )
823+ . collect :: < Vec < CustomAction > > ( )
824+ }
811825 } ;
812826 node. set_custom_actions ( values) ;
813827 }
0 commit comments