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

[PATCH] xcalloc: use CALLOC_ARRAY() when applicable

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2021, 00:55 UTC
Message-ID
<xmqqft0vzzm9.fsf_-_@gitster.g>
In-Reply-To
<xmqqk0q8ynz0.fsf@gitster.g>
These are for codebase before Git 2.31
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * In addition to fixes to topics in flight, I found these in the
   codebase dating as far back as 2.27 days.
 builtin/receive-pack.c | 8 +++-----
 t/helper/test-bloom.c  | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index ea3d0f01af..6a66687e28 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1837,11 +1837,9 @@ static void prepare_shallow_update(struct shallow_info *si)
 	ALLOC_ARRAY(si->used_shallow, si->shallow->nr);
 	assign_shallow_commits_to_refs(si, si->used_shallow, NULL);
 
-	si->need_reachability_test =
-		xcalloc(si->shallow->nr, sizeof(*si->need_reachability_test));
-	si->reachable =
-		xcalloc(si->shallow->nr, sizeof(*si->reachable));
-	si->shallow_ref = xcalloc(si->ref->nr, sizeof(*si->shallow_ref));
+	CALLOC_ARRAY(si->need_reachability_test, si->shallow->nr);
+	CALLOC_ARRAY(si->reachable, si->shallow->nr);
+	CALLOC_ARRAY(si->shallow_ref, si->ref->nr);
 
 	for (i = 0; i < si->nr_ours; i++)
 		si->need_reachability_test[si->ours[i]] = 1;
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index f0aa80b98e..eb7c011ca6 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -65,7 +65,7 @@ int cmd__bloom(int argc, const char **argv)
 		struct bloom_filter filter;
 		int i = 2;
 		filter.len =  (settings.bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;
-		filter.data = xcalloc(filter.len, sizeof(unsigned char));
+		CALLOC_ARRAY(filter.data, filter.len);
 
 		if (argc - 1 < i)
 			usage(bloom_usage);
-- 
2.31.0-186-g100f68d7d5
Previous: René Scharfe.Next: Derrick Stolee
Message 4 of 5 in “git-compat-util.h: drop trailing semicolon from macro definition”
  1. 1/2 git-compat-util.h: drop trailing semicolon from macro definitionRené Scharfe., Mar 13, 2021
  2. 2/2 use CALLOC_ARRAYRené Scharfe., Mar 13, 2021
  3. René Scharfe.Mar 15, 2021
  4. xcalloc: use CALLOC_ARRAY() when applicableJunio C Hamano, Mar 16, 2021
  5. Derrick StoleeMar 16, 2021

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.