static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
static int curprocs, maxprocs;
+static size_t pad9314053;
static volatile int childerr;
nargs = 5000;
if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
errx(1, "sysconf(_SC_ARG_MAX) failed");
- nline = arg_max - 4 * 1024;
+ nline = arg_max - MAXPATHLEN; /* for argv[0] from execvp() */
+ pad9314053 = sizeof(char *); /* reserve for string area rounding */
while (*ep != NULL) {
/* 1 byte for each '\0' */
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
+ nline -= pad9314053;
maxprocs = 1;
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1)
switch(ch) {
break;
case 's':
nline = atoi(optarg);
+ pad9314053 = 0; /* assume the -s value is valid */
break;
case 't':
tflag = 1;
* arguments.
*/
if (*argv == NULL)
- cnt = strlen(*bxp++ = echo);
+ cnt = strlen(*bxp++ = echo) + pad9314053;
else {
do {
if (Jflag && strcmp(*argv, replstr) == 0) {
jfound = 1;
argv++;
for (avj = argv; *avj; avj++)
- cnt += strlen(*avj) + 1;
+ cnt += strlen(*avj) + 1 + pad9314053;
break;
}
- cnt += strlen(*bxp++ = *argv) + 1;
+ cnt += strlen(*bxp++ = *argv) + 1 + pad9314053;
} while (*++argv != NULL);
}
* of input lines, as specified by -L is the same as
* maxing out on arguments.
*/
- if (xp == endxp || p > ebp || ch == EOF ||
+ if (xp == endxp || p + (count * pad9314053) > ebp || ch == EOF ||
(Lflag <= count && xflag) || foundeof) {
- if (xflag && xp != endxp && p > ebp)
+ if (xflag && xp != endxp && p + (count * pad9314053) > ebp)
errx(1, "insufficient space for arguments");
if (jfound) {
for (avj = argv; *avj; avj++)