Skip to contentSkip to conversation

receive-pack: use FLEX_ALLOC_MEM in queue_command()

PATCH In review René Scharfe 2 participants 2 messages Aug 13, 2016 – Aug 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 receive-pack: use FLEX_ALLOC_MEM in queue_command()

Use the macro FLEX_ALLOC_MEM instead of open-coding it. This shortens and simplifies the code a bit.

---
 builtin/receive-pack.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
builtin/receive-pack.c +1 -3
index 92e1213..011db00 100644
@@ -1478,11 +1478,9 @@ static struct command **queue_command(struct command **tail,
 
 	refname = line + 82;
 	reflen = linelen - 82;
-	cmd = xcalloc(1, st_add3(sizeof(struct command), reflen, 1));
+	FLEX_ALLOC_MEM(cmd, ref_name, refname, reflen);
 	hashcpy(cmd->old_sha1, old_sha1);
 	hashcpy(cmd->new_sha1, new_sha1);
-	memcpy(cmd->ref_name, refname, reflen);
-	cmd->ref_name[reflen] = '\0';
 	*tail = cmd;
 	return &cmd->next;
 }
Signature · 1 line
2.9.3
#1 lore raw
Quoted 2 lines · René Scharfe

Use the macro FLEX_ALLOC_MEM instead of open-coding it. This shortens and simplifies the code a bit.

Thanks, looks good (I obviously missed a few opportunities for conversion during the initial introduction of FLEX_ALLOC simply by not noticing; I don't think there is any more reason that this one was not converted).

-Peff