From e10b0a61fb7c817f7c17018d2c39318ce27968be Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:34:17 +0200 Subject: [PATCH] Always add sentinel to capability list before passing it to C --- libosdp/src/pdinfo.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libosdp/src/pdinfo.rs b/libosdp/src/pdinfo.rs index 98b5697..a70fff9 100644 --- a/libosdp/src/pdinfo.rs +++ b/libosdp/src/pdinfo.rs @@ -253,18 +253,27 @@ impl PdInfo { let scbk = if let Some(key) = self.scbk { Box::into_raw(Box::new(key)) as *mut _ } else { - std::ptr::null_mut::() + core::ptr::null_mut::() + }; + let cap = if !self.cap.is_empty() { + let mut cap = self.cap.clone(); + cap.reserve(1); + cap.push(libosdp_sys::osdp_pd_cap { + function_code: -1i8 as u8, + compliance_level: 0, + num_items: 0, + }); + Box::into_raw(cap.into_boxed_slice()) as *mut _ + } else { + core::ptr::null_mut::() }; - let mut cap = self.cap.clone(); - let cap_ptr = cap.as_mut_ptr(); - core::mem::forget(cap); libosdp_sys::osdp_pd_info_t { name: self.name.clone().into_raw(), baud_rate: self.baud_rate, address: self.address, flags: self.flags.bits() as i32, id: self.id.into(), - cap: cap_ptr, + cap: cap as *mut _, channel: self.channel.take().unwrap().into(), scbk, }