1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #4366 from BartMassey-upstream/name-weirdness

coreutils: fixed panic when multi-call binary has funny name
This commit is contained in:
Sylvestre Ledru 2023-04-28 09:27:05 +02:00 committed by GitHub
commit b33986de86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,8 +43,8 @@ fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
}
}
fn name(binary_path: &Path) -> &str {
binary_path.file_stem().unwrap().to_str().unwrap()
fn name(binary_path: &Path) -> Option<&str> {
binary_path.file_stem()?.to_str()
}
fn main() {
@ -54,7 +54,10 @@ fn main() {
let mut args = uucore::args_os();
let binary = binary_path(&mut args);
let binary_as_util = name(&binary);
let binary_as_util = name(&binary).unwrap_or_else(|| {
usage(&utils, "<unknown binary name>");
process::exit(0);
});
// binary name equals util name?
if let Some(&(uumain, _)) = utils.get(binary_as_util) {