From: Jeff King Date: Tue, 28 Mar 2017 19:46:53 GMT Subject: [PATCH 14/18] combine-diff: replace malloc/snprintf with xstrfmt Message-ID: <20170328194653.o2qknaynp45ha7yf@sigill.intra.peff.net> In-Reply-To: <20170328194255.vf7nfzzmmzxsbn36@sigill.intra.peff.net> There's no need to use the magic "100" when a strbuf can do it for us. Signed-off-by: Jeff King --- combine-diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 59501db99..d3560573a 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -292,9 +292,10 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode, enum object_type type; if (S_ISGITLINK(mode)) { - blob = xmalloc(100); - *size = snprintf(blob, 100, - "Subproject commit %s\n", oid_to_hex(oid)); + struct strbuf buf = STRBUF_INIT; + strbuf_addf(&buf, "Subproject commit %s\n", oid_to_hex(oid)); + *size = buf.len; + blob = strbuf_detach(&buf, NULL); } else if (is_null_oid(oid)) { /* deleted blob */ *size = 0; -- 2.12.2.845.g55fcf8b10