Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit 9a127c1

Browse files
author
arkpar
committed
Proper string convertion in open_path
1 parent 32fd0ed commit 9a127c1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern crate libc;
5858

5959
mod ffi;
6060

61-
use std::ffi::CStr;
61+
use std::ffi::{CStr, CString};
6262
use std::marker::PhantomData;
6363
use libc::{wchar_t, size_t, c_int};
6464

@@ -162,7 +162,8 @@ impl HidApi {
162162
/// The path name be determined by calling hid_enumerate(), or a
163163
/// platform-specific path name can be used (eg: /dev/hidraw0 on Linux).
164164
pub fn open_path(&self, device_path: &str) -> HidResult<HidDevice> {
165-
let device = unsafe { ffi::hid_open_path(std::mem::transmute(device_path.as_ptr())) };
165+
let cstr = CString::new(device_path).unwrap();
166+
let device = unsafe { ffi::hid_open_path(cstr.as_ptr()) };
166167

167168
if device.is_null() {
168169
Err("Unable to open hid device")

0 commit comments

Comments
 (0)