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

expr: Add a long input test

Test a stack overflow that was happening on linux for long inputs.
This commit is contained in:
Louis DISPA 2025-03-13 00:00:29 +01:00 committed by Dorian Péron
parent 429a22368a
commit a236f85e9d

View file

@ -374,6 +374,30 @@ fn test_eager_evaluation() {
.stderr_contains("division by zero"); .stderr_contains("division by zero");
} }
#[test]
fn test_long_input() {
// Giving expr an arbitrary long expression should succeed rather than end with a segfault due to a stack overflow.
#[cfg(not(windows))]
const MAX_NUMBER: usize = 40000;
#[cfg(not(windows))]
const RESULT: &str = "800020000\n";
// On windows there is 8192 characters input limit
#[cfg(windows)]
const MAX_NUMBER: usize = 1300; // 7993 characters (with spaces)
#[cfg(windows)]
const RESULT: &str = "845650\n";
let mut args: Vec<String> = vec!["1".to_string()];
for i in 2..=MAX_NUMBER {
args.push('+'.to_string());
args.push(i.to_string());
}
new_ucmd!().args(&args).succeeds().stdout_is(RESULT);
}
/// Regroup the testcases of the GNU test expr.pl /// Regroup the testcases of the GNU test expr.pl
mod gnu_expr { mod gnu_expr {
use crate::common::util::TestScenario; use crate::common::util::TestScenario;