git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] receive-pack: use FLEX_ALLOC_MEM in queue_command()

From
René Scharfe <l.s.r@web.de>
Date
Aug 13, 2016, 15:38 UTC
Message-ID
<57AF3F10.3050508@web.de>

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

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 builtin/receive-pack.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 92e1213..011db00 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -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;
 }
-- 
2.9.3
Next: Jeff King
Message 1 of 2 in “receive-pack: use FLEX_ALLOC_MEM in queue_command()”
  1. receive-pack: use FLEX_ALLOC_MEM in queue_command()René Scharfe, Aug 13, 2016
  2. Jeff KingAug 13, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.