[hackers] [sbase] Allocate the arg buffer in once place || sin
commit 602fd49b5314369cf7a3e7499e9a30896c6ded67
Author: sin <sin_AT_2f30.org>
Date: Wed Jan 8 20:29:34 2014 +0000
Allocate the arg buffer in once place
diff --git a/xargs.c b/xargs.c
index cecba80..7742be2 100644
--- a/xargs.c
+++ b/xargs.c
_AT_@ -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;
_AT_@ -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) {
_AT_@ -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:");
Received on Wed Jan 08 2014 - 21:35:29 CET
This archive was generated by hypermail 2.3.0
: Wed Jan 08 2014 - 21:36:17 CET