Skip to content

Commit 901cc1b

Browse files
authored
Merge pull request ruabmbua#9 from ruabmbua/fix-5-segfault
Fixed issue paritytech#5 & some minor changes
2 parents ac52cb0 + c73246c commit 901cc1b

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hidapi"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = [
55
"Roland Ruckerbauer <[email protected]>",
66
"Osspial <[email protected]>",
@@ -12,7 +12,7 @@ license = "MIT"
1212
keywords = ["hid", "api", "usb","binding", "wrapper"]
1313
build = "build.rs"
1414
links = "hidapi"
15-
documentation = "https://beta.docs.rs/hidapi"
15+
documentation = "https://docs.rs/hidapi"
1616

1717
[dependencies]
1818
libc = "0.2.15"

src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! ```toml
1616
//! [dependencies]
17-
//! hidapi = "0.3"
17+
//! hidapi = "0.4"
1818
//! ```
1919
//! # Example
2020
//!
@@ -59,19 +59,19 @@ pub struct HidApi {
5959
devices: Vec<HidDeviceInfo>,
6060
}
6161

62-
static mut hid_api_lock: bool = false;
62+
static mut HID_API_LOCK: bool = false;
6363

6464
impl HidApi {
6565
/// Initializes the HID
6666
pub fn new() -> HidResult<Self> {
67-
if unsafe { !hid_api_lock } {
67+
if unsafe { !HID_API_LOCK } {
6868

6969
// Initialize the HID and prevent other HIDs from being created
7070
unsafe {
7171
if ffi::hid_init() == -1 {
7272
return Err("Failed to init hid");
7373
}
74-
hid_api_lock = true;
74+
HID_API_LOCK = true;
7575
}
7676

7777

@@ -95,19 +95,16 @@ impl HidApi {
9595
{
9696
let mut current_device = enumeration;
9797

98-
'do_while: loop {
99-
98+
while !current_device.is_null() {
10099
device_vector.push(conv_hid_device_info(current_device));
101-
102-
if (*current_device).next.is_null() {
103-
break 'do_while;
104-
} else {
105-
current_device = (*current_device).next;
106-
}
100+
current_device = (*current_device).next;
107101
}
102+
108103
}
109104

110-
ffi::hid_free_enumeration(enumeration);
105+
if !enumeration.is_null() {
106+
ffi::hid_free_enumeration(enumeration);
107+
}
111108

112109
device_vector
113110
}
@@ -165,7 +162,7 @@ impl Drop for HidApi {
165162
fn drop(&mut self) {
166163
unsafe {
167164
ffi::hid_exit();
168-
hid_api_lock = false;
165+
HID_API_LOCK = false;
169166
}
170167
}
171168
}

0 commit comments

Comments
 (0)