xargs: fix -R so that it accepts negative numbers again

fbc445addf 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:		fbc445addf
MFC after:	1 week
Reviewed by:	des, kevans
Differential Revision:	https://reviews.freebsd.org/D41021
This commit is contained in:
Daniel Tameling 2023-07-13 20:06:14 +00:00 committed by Dag-Erling Smørgrav
parent c3f58005d9
commit 202adb2236
4 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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;