commit 602fd49b5314369cf7a3e7499e9a30896c6ded67
parent 2d64fa94830d0ae76e4cbcb65499ac9fdc9c594b
Author: sin <sin@2f30.org>
Date: Wed, 8 Jan 2014 20:29:34 +0000
Allocate the arg buffer in once place
Diffstat:
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/xargs.c b/xargs.c
@@ -25,7 +25,7 @@ static void spawn(void);
static char **cmd;
static char *argb;
-static size_t argbsz = 1;
+static size_t argbsz;
static size_t argbpos;
static int nerrors = 0;
static char *eofstr;
@@ -65,10 +65,6 @@ main(int argc, char *argv[])
if (!cmd)
eprintf("malloc:");
- argb = malloc(argbsz);
- if (!argb)
- eprintf("malloc:");
-
do {
argsz = 0; i = 0;
if (argc > 0) {
@@ -135,7 +131,7 @@ static void
fillargbuf(int ch)
{
if (argbpos >= argbsz) {
- argbsz *= 2;
+ argbsz = argbpos == 0 ? 1 : argbsz * 2;
argb = realloc(argb, argbsz);
if (!argb)
eprintf("realloc:");