Skip to content

Commit

Permalink
xcb::parse_display has local unsafety instead of global
Browse files Browse the repository at this point in the history
  • Loading branch information
rtbo committed Apr 23, 2024
1 parent eed3c11 commit d4b6da4
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,35 +496,37 @@ pub struct DisplayInfo {
/// assert!(parse_display("0").is_none());
/// ```
pub fn parse_display(name: &str) -> Option<DisplayInfo> {
unsafe {
let name = CString::new(name).unwrap();
let mut hostp: *mut c_char = ptr::null_mut();
let mut display = 0i32;
let mut screen = 0i32;
let name = CString::new(name).unwrap();
let mut hostp: *mut c_char = ptr::null_mut();
let mut display = 0i32;
let mut screen = 0i32;

let success = xcb_parse_display(
let success = unsafe {
xcb_parse_display(
name.as_ptr(),
&mut hostp as *mut _,
&mut display as *mut _,
&mut screen as *mut _,
);
)
};

if success != 0 {
let host = CStr::from_ptr(hostp as *const _)
.to_str()
.unwrap()
.to_string();
if success != 0 {
let host = unsafe { CStr::from_ptr(hostp as *const _) }
.to_str()
.unwrap()
.to_string();

unsafe {
libc::free(hostp as *mut _);

Some(DisplayInfo {
host,
display,
screen,
})
} else {
None
}

Some(DisplayInfo {
host,
display,
screen,
})
} else {
None
}
}

Expand Down

0 comments on commit d4b6da4

Please sign in to comment.