Skip to content

Commit 230e0cf

Browse files
oech3cakebaker
authored andcommitted
logname: reduce range of unsafe block
1 parent 37d07e4 commit 230e0cf

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/uu/logname/src/logname.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ use uucore::translate;
1212
use uucore::{error::UResult, show_error};
1313

1414
fn get_userlogin() -> Option<String> {
15-
unsafe {
16-
let login: *const libc::c_char = libc::getlogin();
17-
if login.is_null() {
18-
None
19-
} else {
20-
Some(String::from_utf8_lossy(CStr::from_ptr(login).to_bytes()).to_string())
21-
}
15+
let login_ptr = unsafe { libc::getlogin() };
16+
if login_ptr.is_null() {
17+
None
18+
} else {
19+
Some(String::from_utf8_lossy(unsafe { CStr::from_ptr(login_ptr) }.to_bytes()).to_string())
2220
}
2321
}
2422

0 commit comments

Comments
 (0)