Convert atoi(3) to stronum(3) which allows to arguments and report proper errors

to the users

Obtained from:	OpenBSD
This commit is contained in:
Baptiste Daroussin 2015-07-14 19:16:14 +00:00
parent f3856d8fcb
commit cffa7aa609
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285552

View file

@ -101,6 +101,7 @@ main(int argc, char *argv[])
int ch, Jflag, nargs, nflag, nline;
size_t linelen;
char *endptr;
const char *errstr;
inpline = replstr = NULL;
ep = environ;
@ -148,19 +149,23 @@ main(int argc, char *argv[])
replstr = optarg;
break;
case 'L':
Lflag = atoi(optarg);
Lflag = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr)
errx(1, "-L %s: %s", optarg, errstr);
break;
case 'n':
nflag = 1;
if ((nargs = atoi(optarg)) <= 0)
errx(1, "illegal argument count");
nargs = strtonum(optarg, 1, INT_MAX, &errstr);
if (errstr)
errx(1, "-n %s: %s", optarg, errstr);
break;
case 'o':
oflag = 1;
break;
case 'P':
if ((maxprocs = atoi(optarg)) <= 0)
errx(1, "max. processes must be >0");
maxprocs = strtonum(optarg, 1, INT_MAX, &errstr);
if (errstr)
errx(1, "-P %s: %s", optarg, errstr);
break;
case 'p':
pflag = 1;
@ -179,7 +184,9 @@ main(int argc, char *argv[])
errx(1, "replsize must be a number");
break;
case 's':
nline = atoi(optarg);
nline = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr)
errx(1, "-s %s: %s", optarg, errstr);
break;
case 't':
tflag = 1;