Skip to content

Commit

Permalink
Update implementation of ffi string handling in into_device_info
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-wh committed Oct 29, 2024
1 parent c40f611 commit 6cae8dd
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions wooting-analog-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,13 @@ impl DeviceInfo_FFI {
product_id: self.product_id.clone(),
// In this case we use CStr rather than CString as we don't want the memory to be dropped here which may cause a double free
// We leave it up to ffi interface to drop the memory
manufacturer_name: unsafe {
CStr::from_ptr(self.manufacturer_name)
.to_str()
.unwrap()
.to_owned()
manufacturer_name: {
let cstr = unsafe { CStr::from_ptr(self.manufacturer_name) };
String::from_utf8_lossy(cstr.to_bytes()).to_string()
},
device_name: unsafe {
CStr::from_ptr(self.device_name)
.to_str()
.unwrap()
.to_owned()
device_name: {
let cstr = unsafe { CStr::from_ptr(self.device_name) };
String::from_utf8_lossy(cstr.to_bytes()).to_string()
},
device_id: self.device_id.clone(),
device_type: self.device_type.clone(),
Expand Down

0 comments on commit 6cae8dd

Please sign in to comment.