nice: -n huge_num true (#10213)

This commit is contained in:
oech3
2026-01-19 00:02:28 +09:00
committed by GitHub
parent 0e509474d1
commit ca13e3391a
2 changed files with 43 additions and 6 deletions
+13 -6
View File
@@ -9,6 +9,7 @@ use clap::{Arg, ArgAction, Command};
use libc::PRIO_PROCESS;
use std::ffi::OsString;
use std::io::{Error, ErrorKind, Write};
use std::num::IntErrorKind;
use std::os::unix::process::CommandExt;
use std::process;
@@ -23,6 +24,8 @@ pub mod options {
pub static COMMAND: &str = "COMMAND";
}
const NICE_BOUND_NO_OVERFLOW: i32 = 50;
fn is_prefix_of(maybe_prefix: &str, target: &str, min_match: usize) -> bool {
if maybe_prefix.len() < min_match || maybe_prefix.len() > target.len() {
return false;
@@ -126,12 +129,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
match nstr.parse::<i32>() {
Ok(num) => num,
Err(e) => {
return Err(USimpleError::new(
125,
translate!("nice-error-invalid-number", "value" => nstr.clone(), "error" => e),
));
}
Err(e) => match e.kind() {
IntErrorKind::PosOverflow => NICE_BOUND_NO_OVERFLOW,
IntErrorKind::NegOverflow => -NICE_BOUND_NO_OVERFLOW,
_ => {
return Err(USimpleError::new(
125,
translate!("nice-error-invalid-number", "value" => nstr.clone(), "error" => e),
));
}
},
}
}
None => {
+30
View File
@@ -90,3 +90,33 @@ fn test_trailing_empty_adjustment() {
"error: The argument '--adjustment <adjustment>' requires a value but none was supplied",
);
}
#[test]
fn test_nice_huge() {
new_ucmd!()
.args(&[
"-n",
"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"true",
])
.succeeds()
.no_stdout();
}
#[test]
fn test_nice_huge_negative() {
new_ucmd!().args(&["-n", "-9999999999", "true"]).succeeds();
//.stderr_contains("Permission denied"); Depending on platform?
}
#[test]
fn test_sign_middle() {
new_ucmd!()
.args(&["-n", "-2+4", "true"])
.fails_with_code(125)
.no_stdout()
.stderr_contains("invalid");
}
//uu: "-2+4" is not a valid number: invalid digit found in string
//gnu: invalid adjustment `-2+4'
//Both message is fine