git: 202adb223610 - main - xargs: fix -R so that it accepts negative numbers again
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 13 Jul 2023 21:37:24 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=202adb2236104141dc02d512084a3cc4bbe734c7 commit 202adb2236104141dc02d512084a3cc4bbe734c7 Author: Daniel Tameling <tamelingdaniel@gmail.com> AuthorDate: 2023-07-13 20:06:14 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-07-13 21:35:23 +0000 xargs: fix -R so that it accepts negative numbers again fbc445addf9 converted the parsing of arguments to strtonum but made the accepted range for -R too restrictive. As documented in the man page, it should accept negative numbers. Added a test for this, which was provided by Jose Luis Duran. Fixes: fbc445addf9 MFC after: 1 week Reviewed by: des, kevans Differential Revision: https://reviews.freebsd.org/D41021 --- usr.bin/xargs/tests/Makefile | 1 + usr.bin/xargs/tests/regress.R-1.out | 4 ++++ usr.bin/xargs/tests/regress.sh | 3 ++- usr.bin/xargs/xargs.c | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/usr.bin/xargs/tests/Makefile b/usr.bin/xargs/tests/Makefile index 228c1d545781..6bb861a6d27a 100644 --- a/usr.bin/xargs/tests/Makefile +++ b/usr.bin/xargs/tests/Makefile @@ -15,6 +15,7 @@ ${PACKAGE}FILES+= regress.J.out ${PACKAGE}FILES+= regress.L.out ${PACKAGE}FILES+= regress.P1.out ${PACKAGE}FILES+= regress.R.out +${PACKAGE}FILES+= regress.R-1.out ${PACKAGE}FILES+= regress.in ${PACKAGE}FILES+= regress.n1.out ${PACKAGE}FILES+= regress.n2.out diff --git a/usr.bin/xargs/tests/regress.R-1.out b/usr.bin/xargs/tests/regress.R-1.out new file mode 100644 index 000000000000..7bdf58090c60 --- /dev/null +++ b/usr.bin/xargs/tests/regress.R-1.out @@ -0,0 +1,4 @@ +The quick brown quick brown quick brown quick brownquick brown quick brown quick brown +The fox jumped fox jumped fox jumped fox jumpedfox jumped fox jumped fox jumped +The over the lazy over the lazy over the lazy over the lazyover the lazy over the lazy over the lazy +The dog dog dog dogdog dog dog diff --git a/usr.bin/xargs/tests/regress.sh b/usr.bin/xargs/tests/regress.sh index e79bfd4352fa..ed81d66bf2a6 100644 --- a/usr.bin/xargs/tests/regress.sh +++ b/usr.bin/xargs/tests/regress.sh @@ -1,6 +1,6 @@ # $FreeBSD$ -echo 1..20 +echo 1..21 REGRESSION_START($1) @@ -10,6 +10,7 @@ REGRESSION_TEST(`J', `xargs -J% echo The % again. <${SRCDIR}/regress.in') REGRESSION_TEST(`L', `xargs -L3 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`P1', `xargs -P1 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`R', `xargs -I% -R1 echo The % % % %% % % <${SRCDIR}/regress.in') +REGRESSION_TEST(`R-1', `xargs -I% -R-1 echo The % % % %% % % <${SRCDIR}/regress.in') REGRESSION_TEST(`n1', `xargs -n1 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`n2', `xargs -n2 echo <${SRCDIR}/regress.in') REGRESSION_TEST(`n2P0',`xargs -n2 -P0 echo <${SRCDIR}/regress.in | sort') diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index e832cbb35a31..94a32d04fd67 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -200,7 +200,7 @@ main(int argc, char *argv[]) pflag = 1; break; case 'R': - Rflag = (int)strtonum(optarg, 0, INT_MAX, &errstr); + Rflag = (int)strtonum(optarg, INT_MIN, INT_MAX, &errstr); if (errstr) errx(1, "-%c %s: %s", ch, optarg, errstr); break;