contrib/chg/hgclient.c
changeset 30756 1f9684fe94cc
parent 30751 e882c7bb5a0b
child 31941 ac5527021097
--- a/contrib/chg/hgclient.c	Tue Jan 10 09:32:27 2017 +0100
+++ b/contrib/chg/hgclient.c	Wed Jan 11 23:39:24 2017 +0800
@@ -366,9 +366,11 @@
 
 static void updateprocname(hgclient_t *hgc)
 {
-	size_t n = (size_t)snprintf(hgc->ctx.data, hgc->ctx.maxdatasize,
+	int r = snprintf(hgc->ctx.data, hgc->ctx.maxdatasize,
 			"chg[worker/%d]", (int)getpid());
-	hgc->ctx.datasize = n;
+	if (r < 0 || (size_t)r >= hgc->ctx.maxdatasize)
+		abortmsg("insufficient buffer to write procname (r = %d)", r);
+	hgc->ctx.datasize = (size_t)r;
 	writeblockrequest(hgc, "setprocname");
 }