Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ use uucore::{format_usage, help_about, help_section, help_usage, show_error};

macro_rules! cstr2cow {
($v:expr) => {
unsafe { CStr::from_ptr($v).to_string_lossy() }
unsafe {
let ptr = $v;
// Must be not null to call cstr2cow
if ptr.is_null() {
None
} else {
Some({ CStr::from_ptr(ptr) }.to_string_lossy())
}
}
};
}

Expand Down Expand Up @@ -451,8 +459,8 @@ fn pretty(possible_pw: Option<Passwd>) {
let login = cstr2cow!(getlogin().cast_const());
let rid = getuid();
if let Ok(p) = Passwd::locate(rid) {
if login == p.name {
println!("login\t{login}");
if let Some(user_name) = login {
println!("login\t{user_name}");
}
println!("uid\t{}", p.name);
} else {
Expand Down
13 changes: 1 addition & 12 deletions tests/by-util/test_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,8 @@ fn test_id_real() {
fn test_id_pretty_print() {
// `-p` is BSD only and not supported on GNU's `id`
let username = whoami();

let result = new_ucmd!().arg("-p").run();
if result.stdout_str().trim().is_empty() {
// this fails only on: "MinRustV (ubuntu-latest, feat_os_unix)"
// `rustc 1.40.0 (73528e339 2019-12-16)`
// run: /home/runner/work/coreutils/coreutils/target/debug/coreutils id -p
// thread 'test_id::test_id_pretty_print' panicked at 'Command was expected to succeed.
// stdout =
// stderr = ', tests/common/util.rs:157:13
println!("test skipped:");
} else {
result.success().stdout_contains(username);
}
result.success().stdout_contains(username);
}

#[test]
Expand Down
Loading