-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing checks for NULL pointers
- Loading branch information
1 parent
e249f75
commit c964309
Showing
7 changed files
with
37 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ cfg_if::cfg_if! { | |
|
||
pub(crate) mod network_helper; | ||
pub(crate) mod users; | ||
pub(crate) mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Take a look at the license at the top of the repository in the LICENSE file. | ||
|
||
use libc::c_char; | ||
|
||
pub(crate) fn cstr_to_rust(c: *const c_char) -> Option<String> { | ||
cstr_to_rust_with_size(c, None) | ||
} | ||
|
||
pub(crate) fn cstr_to_rust_with_size(c: *const c_char, size: Option<usize>) -> Option<String> { | ||
if c.is_null() { | ||
return None; | ||
} | ||
let mut s = match size { | ||
Some(len) => Vec::with_capacity(len), | ||
None => Vec::new(), | ||
}; | ||
let mut i = 0; | ||
unsafe { | ||
loop { | ||
let value = *c.offset(i) as u8; | ||
if value == 0 { | ||
break; | ||
} | ||
s.push(value); | ||
i += 1; | ||
} | ||
String::from_utf8(s).ok() | ||
} | ||
} |