Skip to content

Commit 0dc3b03

Browse files
peffgitster
authored andcommitted
combine-diff: replace malloc/snprintf with xstrfmt
There's no need to use the magic "100" when a strbuf can do it for us. Signed-off-by: Jeff King <[email protected]>
1 parent 5b1ef2c commit 0dc3b03

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

combine-diff.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
292292
enum object_type type;
293293

294294
if (S_ISGITLINK(mode)) {
295-
blob = xmalloc(100);
296-
*size = snprintf(blob, 100,
297-
"Subproject commit %s\n", oid_to_hex(oid));
295+
struct strbuf buf = STRBUF_INIT;
296+
strbuf_addf(&buf, "Subproject commit %s\n", oid_to_hex(oid));
297+
*size = buf.len;
298+
blob = strbuf_detach(&buf, NULL);
298299
} else if (is_null_oid(oid)) {
299300
/* deleted blob */
300301
*size = 0;

0 commit comments

Comments
 (0)