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:
parent
09018605c0
commit
d2f1cdda38
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user