changeset 28166:c6e0c2533e5f

chg: use mallocx and reallocx in hgclient This patch simplifies the code a bit, and reduces the binary size a little.
author Jun Wu <quark@fb.com>
date Wed, 17 Feb 2016 15:08:09 +0000
parents c6705c6303dd
children 66f6dad20c19
files contrib/chg/hgclient.c
diffstat 1 files changed, 3 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/hgclient.c	Wed Feb 17 14:51:38 2016 +0000
+++ b/contrib/chg/hgclient.c	Wed Feb 17 15:08:09 2016 +0000
@@ -84,10 +84,7 @@
 
 	newsize = defaultdatasize
 		* ((newsize + defaultdatasize - 1) / defaultdatasize);
-	char *p = realloc(ctx->data, newsize);
-	if (!p)
-		abortmsg("failed to allocate buffer");
-	ctx->data = p;
+	ctx->data = reallocx(ctx->data, newsize);
 	ctx->maxdatasize = newsize;
 	debugmsg("enlarge context buffer to %zu", ctx->maxdatasize);
 }
@@ -195,9 +192,7 @@
 	for (;;) {
 		if (nargs + 1 >= maxnargs) {  /* including last NULL */
 			maxnargs += 256;
-			args = realloc(args, maxnargs * sizeof(args[0]));
-			if (!args)
-				abortmsg("failed to allocate args buffer");
+			args = reallocx(args, maxnargs * sizeof(args[0]));
 		}
 		args[nargs] = s;
 		nargs++;
@@ -432,9 +427,7 @@
 			 addr.sun_path, errno);
 	}
 
-	hgclient_t *hgc = malloc(sizeof(hgclient_t));
-	if (!hgc)
-		abortmsg("failed to allocate hgclient object");
+	hgclient_t *hgc = mallocx(sizeof(hgclient_t));
 	memset(hgc, 0, sizeof(*hgc));
 	hgc->sockfd = fd;
 	initcontext(&hgc->ctx);