git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] receive-pack: use FLEX_ALLOC_MEM in queue_command()
@ 2016-08-13 15:38 René Scharfe
  2016-08-13 18:34 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2016-08-13 15:38 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Jeff King

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] receive-pack: use FLEX_ALLOC_MEM in queue_command()
  2016-08-13 15:38 [PATCH] receive-pack: use FLEX_ALLOC_MEM in queue_command() René Scharfe
@ 2016-08-13 18:34 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2016-08-13 18:34 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Sat, Aug 13, 2016 at 05:38:56PM +0200, René Scharfe wrote:

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-14 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-13 15:38 [PATCH] receive-pack: use FLEX_ALLOC_MEM in queue_command() René Scharfe
2016-08-13 18:34 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).