diff options
author | Rob Landley <rob@landley.net> | 2019-10-28 01:05:43 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-10-28 01:05:43 -0500 |
commit | b39584e7048a44889ead0421dac7a7aae7e0a61a (patch) | |
tree | a56cb2a35e89f7c69d7213887c29f6f6de8d10a0 | |
parent | b28b2a60c6d9c7bbbee14cf23ac6c7fa7c193e01 (diff) | |
download | toybox-b39584e7048a44889ead0421dac7a7aae7e0a61a.tar.gz |
More xargs cleanup, with one possible accounting error but not what fixes
the -0 "argument too long" issue.
-rw-r--r-- | toys/posix/xargs.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index 725eb593..11cc56ee 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -80,8 +80,10 @@ static char *handle_entries(char *data, char **entry) // -0 support } else { - TT.bytes += sizeof(char *)+strlen(data)+1; - if ((TT.s && TT.bytes >= TT.s) || (TT.n && TT.entries >= TT.n)) return data; + long bytes = TT.bytes+sizeof(char *)+strlen(data)+1; + + if (bytes >= TT.s || (TT.n && TT.entries >= TT.n)) return data; + TT.bytes = bytes; if (entry) entry[TT.entries] = data; TT.entries++; } @@ -113,8 +115,8 @@ void xargs_main(void) } // count entries - for (entries = 0, bytes = -1; entries < toys.optc; entries++, bytes++) - bytes += strlen(toys.optargs[entries]) + sizeof(char *)*!FLAG(s); + for (entries = 0, bytes = -1; entries < toys.optc; entries++) + bytes += strlen(toys.optargs[entries])+1+sizeof(char *)*!FLAG(s); if (bytes >= TT.s) error_exit("argument too long"); // Loop through exec chunks. @@ -196,13 +198,8 @@ void xargs_main(void) // Abritrary number of execs, can't just leak memory each time... skip: - while (dlist) { - struct double_list *dtemp = dlist->next; - - free(dlist->data); - free(dlist); - dlist = dtemp; - } + llist_traverse(dlist, llist_free_double); + dlist = 0; free(out); } if (TT.tty) fclose(TT.tty); |