Skip to content

Commit

Permalink
Fix panic with wooting_analog_get_connected_devices_info
Browse files Browse the repository at this point in the history
There seems to have been an instance where swap_with_slice panicked because `c_devices.len()` was `0` for some reason.
I'm no Rust expert, but this logic seems to be working to correctly map devices into c_devices.
  • Loading branch information
Sainan committed Oct 25, 2024
1 parent c588569 commit 0ec08bd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wooting-analog-sdk/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ pub extern "C" fn wooting_analog_get_connected_devices_info(
devices.truncate(device_no);
// Convert all the DeviceInfo's into DeviceInfo_C pointers
let c_devices: Vec<*mut DeviceInfo_FFI> = devices
.drain(..)
.map(|dev| Box::into_raw(Box::new(dev.into())))
.iter()
.map(|dev| Box::into_raw(Box::new((*dev).clone().into())))
.collect();

buff.swap_with_slice(c_devices.clone().as_mut());
Expand Down

0 comments on commit 0ec08bd

Please sign in to comment.