From 9a1e379a9dde3c2d85eb0c5048b7984ed4b28721 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 4 Jun 2026 20:41:58 +0200 Subject: [PATCH] fix: avoid panic on -fprintf with missing arguments (#698) Fixes #696 --- src/find/matchers/mod.rs | 2 +- tests/test_find.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index a3abe4f..79d1a8f 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -477,7 +477,7 @@ fn build_matcher_tree( Some(Printer::new(PrintDelimiter::Newline, Some(file)).into_box()) } "-fprintf" => { - if i >= args.len() - 2 { + if i + 2 >= args.len() { return Err(From::from(format!("missing argument to {}", args[i]))); } diff --git a/tests/test_find.rs b/tests/test_find.rs index c51891f..1c288a7 100644 --- a/tests/test_find.rs +++ b/tests/test_find.rs @@ -985,6 +985,21 @@ fn find_fprintf() { assert!(contents.contains("test_data/simple")); } +#[test] +fn find_fprintf_missing_arguments() { + // Regression test: `-fprintf` with no file/format argument must report a + // missing-argument error instead of panicking (see issue #696). + ucmd() + .args(&["-fprintf"]) + .fails() + .stderr_contains("missing argument to -fprintf"); + + ucmd() + .args(&["-fprintf", "/tmp/find_fprintf_out"]) + .fails() + .stderr_contains("missing argument to -fprintf"); +} + #[test] fn find_ls() { ucmd()