Commit 3517e6d7 authored by topjohnwu's avatar topjohnwu

Handle nullptr char* in Rust

parent 67845f9c
......@@ -108,7 +108,11 @@ macro_rules! cstr {
}
pub fn ptr_to_str<'a, T>(ptr: *const T) -> &'a str {
unsafe { CStr::from_ptr(ptr.cast()) }.to_str().unwrap_or("")
if ptr.is_null() {
"(null)"
} else {
unsafe { CStr::from_ptr(ptr.cast()) }.to_str().unwrap_or("")
}
}
pub fn errno() -> &'static mut i32 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment