From 602fd49b5314369cf7a3e7499e9a30896c6ded67 Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 8 Jan 2014 20:29:34 +0000 Subject: [PATCH] Allocate the arg buffer in once place --- xargs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/xargs.c b/xargs.c index cecba80..7742be2 100644 --- 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:");