git: fbc445addf91 - main - xargs: Consistently use strtonum() to parse arguments.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 05 Jun 2023 18:51:23 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=fbc445addf9183d180bb8b488281617bb19d9242 commit fbc445addf9183d180bb8b488281617bb19d9242 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-06-05 18:50:54 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-06-05 18:50:54 +0000 xargs: Consistently use strtonum() to parse arguments. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D40425 --- usr.bin/xargs/xargs.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index eb496d8e09fe..e832cbb35a31 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -124,7 +124,6 @@ main(int argc, char *argv[]) int ch, Jflag, nargs, nflag, nline; size_t linelen; struct rlimit rl; - char *endptr; const char *errstr; inpline = replstr = NULL; @@ -175,23 +174,23 @@ main(int argc, char *argv[]) replstr = optarg; break; case 'L': - Lflag = strtonum(optarg, 0, INT_MAX, &errstr); + Lflag = (int)strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) - errx(1, "-L %s: %s", optarg, errstr); + errx(1, "-%c %s: %s", ch, optarg, errstr); break; case 'n': nflag = 1; - nargs = strtonum(optarg, 1, INT_MAX, &errstr); + nargs = (int)strtonum(optarg, 1, INT_MAX, &errstr); if (errstr) - errx(1, "-n %s: %s", optarg, errstr); + errx(1, "-%c %s: %s", ch, optarg, errstr); break; case 'o': oflag = 1; break; case 'P': - maxprocs = strtonum(optarg, 0, INT_MAX, &errstr); + maxprocs = (int)strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) - errx(1, "-P %s: %s", optarg, errstr); + errx(1, "-%c %s: %s", ch, optarg, errstr); if (getrlimit(RLIMIT_NPROC, &rl) != 0) errx(1, "getrlimit failed"); if (maxprocs == 0 || maxprocs > rl.rlim_cur) @@ -201,22 +200,22 @@ main(int argc, char *argv[]) pflag = 1; break; case 'R': - Rflag = strtol(optarg, &endptr, 10); - if (*endptr != '\0') - errx(1, "replacements must be a number"); + Rflag = (int)strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "-%c %s: %s", ch, optarg, errstr); break; case 'r': /* GNU compatibility */ break; case 'S': - Sflag = strtoul(optarg, &endptr, 10); - if (*endptr != '\0') - errx(1, "replsize must be a number"); + Sflag = (int)strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "-%c %s: %s", ch, optarg, errstr); break; case 's': - nline = strtonum(optarg, 0, INT_MAX, &errstr); + nline = (int)strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) - errx(1, "-s %s: %s", optarg, errstr); + errx(1, "-%c %s: %s", ch, optarg, errstr); break; case 't': tflag = 1;