fix null handling of array fields in autogen properties (#2518)

* add UnalignedSlice

* Revert "add UnalignedSlice"

This reverts commit 8bb1603ed3.

* add null check

* clippy

* rerun ci
This commit is contained in:
Martin Charles 2024-04-19 03:32:23 -05:00 committed by GitHub
parent 7827b6b22a
commit 3fb4a30a9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,14 +92,19 @@ fn properties_output(members: &[PropertiesMember]) -> TokenStream {
let len_field_name = Ident::new(len_field_name.as_str(), Span::call_site());
quote! {
properties_ffi.#ffi_member.map(|s|
unsafe {
properties_ffi.#ffi_member.and_then(|s| {
let ptr = s #ffi_member_field .#ffi_name .cast_const();
if ptr.is_null() {
return None;
};
Some(unsafe {
std::slice::from_raw_parts(
s #ffi_member_field .#ffi_name .cast_const(),
ptr,
s #ffi_member_field .#len_field_name as _,
)
}
)
})
})
}
} else {
quote! { properties_ffi.#ffi_member.map(|s| s #ffi_member_field .#ffi_name) }