Author: bapt
Date: Tue Jul 14 19:16:14 2015
New Revision: 285552
URL: https://svnweb.freebsd.org/changeset/base/285552

Log:
  Convert atoi(3) to stronum(3) which allows to arguments and report proper 
errors
  to the users
  
  Obtained from:        OpenBSD

Modified:
  head/usr.bin/xargs/xargs.c

Modified: head/usr.bin/xargs/xargs.c
==============================================================================
--- head/usr.bin/xargs/xargs.c  Tue Jul 14 19:11:16 2015        (r285551)
+++ head/usr.bin/xargs/xargs.c  Tue Jul 14 19:16:14 2015        (r285552)
@@ -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;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to