git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH] xcalloc: use CALLOC_ARRAY() when applicable
Date: Mon, 15 Mar 2021 17:55:10 -0700	[thread overview]
Message-ID: <xmqqft0vzzm9.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqqk0q8ynz0.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 15 Mar 2021 16:52:03 -0700")

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


  parent reply	other threads:[~2021-03-16  0:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 16:10 [PATCH 1/2] git-compat-util.h: drop trailing semicolon from macro definition René Scharfe.
2021-03-13 16:17 ` [PATCH 2/2] use CALLOC_ARRAY René Scharfe.
     [not found]   ` <xmqq35ww1amf.fsf@gitster.g>
2021-03-15 22:35     ` René Scharfe.
     [not found]       ` <xmqqk0q8ynz0.fsf@gitster.g>
2021-03-16  0:55         ` Junio C Hamano [this message]
2021-03-16 11:43           ` [PATCH] xcalloc: use CALLOC_ARRAY() when applicable Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqft0vzzm9.fsf_-_@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).