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

[PATCH 2/2] run-command: use ALLOC_ARRAY

From
René Scharfe <l.s.r@web.de>
Date
Oct 1, 2017, 15:14 UTC
Message-ID
<6343155c-0986-06b0-8ced-146b23b8a137@web.de>
In-Reply-To
<c4abb7ac-dafd-57f2-8b46-45d610d656c4@web.de>

Use the macro ALLOC_ARRAY to allocate an array. This is shorter and eaasier, as it automatically infers the size of elements.

Patch generated with Coccinelle and contrib/coccinelle/array.cocci.
Signeg-off-by: Rene Scharfe <l.s.r@web.de>
---
 run-command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/run-command.c b/run-command.c
index b5e6eb37c0..014b2165b5 100644
--- a/run-command.c
+++ b/run-command.c
@@ -452,7 +452,7 @@ static char **prep_childenv(const char *const *deltaenv)
 	}
 
 	/* Create an array of 'char *' to be used as the childenv */
-	childenv = xmalloc((env.nr + 1) * sizeof(char *));
+	ALLOC_ARRAY(childenv, env.nr + 1);
 	for (i = 0; i < env.nr; i++)
 		childenv[i] = env.items[i].util;
 	childenv[env.nr] = NULL;
-- 
2.14.2
Previous: René ScharfeNext: Stefan Beller
Message 2 of 3 in “coccinelle: remove parentheses that become unnecessary”
  1. 1/2 coccinelle: remove parentheses that become unnecessaryRené Scharfe, Oct 1, 2017
  2. 2/2 run-command: use ALLOC_ARRAYRené Scharfe, Oct 1, 2017
  3. Stefan BellerOct 2, 2017

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.