git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v2 02/21] Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ
Date: Sun, 26 Mar 2017 16:01:24 +0000	[thread overview]
Message-ID: <20170326160143.769630-3-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170326160143.769630-1-sandals@crustytoothpaste.net>

Since we will likely be introducing a new hash function at some point,
and that hash function might be longer than 40 hex characters, use the
constant GIT_MAX_HEXSZ, which is designed to be suitable for
allocations, instead of GIT_SHA1_HEXSZ.  This will ease the transition
down the line by distinguishing between places where we need to allocate
memory suitable for the largest hash from those where we need to handle
the current hash.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 bisect.c              | 2 +-
 builtin/blame.c       | 4 ++--
 builtin/merge-index.c | 2 +-
 builtin/merge.c       | 2 +-
 builtin/rev-list.c    | 2 +-
 diff.c                | 4 ++--
 hex.c                 | 2 +-
 sha1_file.c           | 2 +-
 sha1_name.c           | 6 +++---
 transport.c           | 2 +-
 10 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/bisect.c b/bisect.c
index 30808cadf7..21c3e34636 100644
--- a/bisect.c
+++ b/bisect.c
@@ -682,7 +682,7 @@ static int is_expected_rev(const struct object_id *oid)
 
 static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
 {
-	char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
+	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 
 	memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
 	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
diff --git a/builtin/blame.c b/builtin/blame.c
index f7aa95f4ba..07506a3e45 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1890,7 +1890,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
 	int cnt;
 	const char *cp;
 	struct origin *suspect = ent->suspect;
-	char hex[GIT_SHA1_HEXSZ + 1];
+	char hex[GIT_MAX_HEXSZ + 1];
 
 	oid_to_hex_r(hex, &suspect->commit->object.oid);
 	printf("%s %d %d %d\n",
@@ -1928,7 +1928,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 	const char *cp;
 	struct origin *suspect = ent->suspect;
 	struct commit_info ci;
-	char hex[GIT_SHA1_HEXSZ + 1];
+	char hex[GIT_MAX_HEXSZ + 1];
 	int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
 
 	get_commit_info(suspect->commit, &ci, 1);
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index 2d1b6db6bd..c99443b095 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -9,7 +9,7 @@ static int merge_entry(int pos, const char *path)
 {
 	int found;
 	const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL };
-	char hexbuf[4][GIT_SHA1_HEXSZ + 1];
+	char hexbuf[4][GIT_MAX_HEXSZ + 1];
 	char ownbuf[4][60];
 
 	if (pos >= active_nr)
diff --git a/builtin/merge.c b/builtin/merge.c
index 7554b8d412..a2cceea3fb 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1296,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (verify_signatures) {
 		for (p = remoteheads; p; p = p->next) {
 			struct commit *commit = p->item;
-			char hex[GIT_SHA1_HEXSZ + 1];
+			char hex[GIT_MAX_HEXSZ + 1];
 			struct signature_check signature_check;
 			memset(&signature_check, 0, sizeof(signature_check));
 
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0aa93d5891..bcf77f0b8a 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -212,7 +212,7 @@ static void print_var_int(const char *var, int val)
 static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 {
 	int cnt, flags = info->flags;
-	char hex[GIT_SHA1_HEXSZ + 1] = "";
+	char hex[GIT_MAX_HEXSZ + 1] = "";
 	struct commit_list *tried;
 	struct rev_info *revs = info->revs;
 
diff --git a/diff.c b/diff.c
index a628ac3a95..330b640c68 100644
--- a/diff.c
+++ b/diff.c
@@ -398,7 +398,7 @@ static struct diff_tempfile {
 	 */
 	const char *name;
 
-	char hex[GIT_SHA1_HEXSZ + 1];
+	char hex[GIT_MAX_HEXSZ + 1];
 	char mode[10];
 
 	/*
@@ -4219,7 +4219,7 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
 	 * uniqueness across all objects (statistically speaking).
 	 */
 	if (abblen < GIT_SHA1_HEXSZ - 3) {
-		static char hex[GIT_SHA1_HEXSZ + 1];
+		static char hex[GIT_MAX_HEXSZ + 1];
 		if (len < abblen && abblen <= len + 2)
 			xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
 		else
diff --git a/hex.c b/hex.c
index eab7b626ee..28b44118cb 100644
--- a/hex.c
+++ b/hex.c
@@ -85,7 +85,7 @@ char *oid_to_hex_r(char *buffer, const struct object_id *oid)
 char *sha1_to_hex(const unsigned char *sha1)
 {
 	static int bufno;
-	static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
+	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
 	return sha1_to_hex_r(hexbuffer[bufno], sha1);
 }
diff --git a/sha1_file.c b/sha1_file.c
index 71063890ff..e763000d34 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3759,7 +3759,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
 		strbuf_addf(path, "/%s", de->d_name);
 
 		if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2)  {
-			char hex[GIT_SHA1_HEXSZ+1];
+			char hex[GIT_MAX_HEXSZ+1];
 			struct object_id oid;
 
 			snprintf(hex, sizeof(hex), "%02x%s",
diff --git a/sha1_name.c b/sha1_name.c
index cda9e49b12..964201bc26 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -15,7 +15,7 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
 
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
-	char hex_pfx[GIT_SHA1_HEXSZ + 1];
+	char hex_pfx[GIT_MAX_HEXSZ + 1];
 	unsigned char bin_pfx[GIT_SHA1_RAWSZ];
 
 	disambiguate_hint_fn fn;
@@ -80,7 +80,7 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
 static void find_short_object_filename(struct disambiguate_state *ds)
 {
 	struct alternate_object_database *alt;
-	char hex[GIT_SHA1_HEXSZ];
+	char hex[GIT_MAX_HEXSZ];
 	static struct alternate_object_database *fakeent;
 
 	if (!fakeent) {
@@ -509,7 +509,7 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
 const char *find_unique_abbrev(const unsigned char *sha1, int len)
 {
 	static int bufno;
-	static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
+	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	char *hex = hexbuffer[bufno];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
 	find_unique_abbrev_r(hex, sha1, len);
diff --git a/transport.c b/transport.c
index 417ed7f19f..8a90b0c29b 100644
--- a/transport.c
+++ b/transport.c
@@ -447,7 +447,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
 
 static int measure_abbrev(const struct object_id *oid, int sofar)
 {
-	char hex[GIT_SHA1_HEXSZ + 1];
+	char hex[GIT_MAX_HEXSZ + 1];
 	int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
 
 	return (w < sofar) ? sofar : w;

  parent reply	other threads:[~2017-03-26 16:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-26 16:01 [PATCH v2 00/21] object_id part 7 brian m. carlson
2017-03-26 16:01 ` [PATCH v2 01/21] Define new hash-size constants for allocating memory brian m. carlson
2017-03-26 16:01 ` brian m. carlson [this message]
2017-03-26 16:01 ` [PATCH v2 03/21] Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ brian m. carlson
2017-03-26 16:01 ` [PATCH v2 04/21] builtin/diff: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 05/21] builtin/pull: convert portions " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 06/21] builtin/receive-pack: fix incorrect pointer arithmetic brian m. carlson
2017-03-28  6:51   ` Jeff King
2017-03-28 16:58     ` Junio C Hamano
2017-03-26 16:01 ` [PATCH v2 07/21] builtin/receive-pack: convert portions to struct object_id brian m. carlson
2017-03-28  7:07   ` Jeff King
2017-03-29 23:21     ` brian m. carlson
2017-03-30  1:37       ` Jeff King
2017-03-26 16:01 ` [PATCH v2 08/21] fsck: convert init_skiplist " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 09/21] parse-options-cb: convert sha1_array_append caller " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 10/21] test-sha1-array: convert most code " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 11/21] sha1_name: convert struct disambiguate_state to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 12/21] sha1_name: convert disambiguate_hint_fn to take object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 13/21] submodule: convert check_for_new_submodule_commits to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 14/21] builtin/pull: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 15/21] sha1-array: convert internal storage for struct sha1_array to object_id brian m. carlson
2017-03-28  7:24   ` Jeff King
2017-03-26 16:01 ` [PATCH v2 16/21] Make sha1_array_append take a struct object_id * brian m. carlson
2017-03-28  7:26   ` Jeff King
2017-03-28 17:27   ` Junio C Hamano
2017-03-29  0:06     ` brian m. carlson
2017-03-29 15:14       ` Junio C Hamano
2017-03-29 22:28         ` brian m. carlson
2017-03-26 16:01 ` [PATCH v2 17/21] Convert remaining callers of sha1_array_lookup to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 18/21] Convert sha1_array_lookup to take struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 19/21] Convert sha1_array_for_each_unique and for_each_abbrev to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 20/21] Rename sha1_array to oid_array brian m. carlson
2017-03-26 16:01 ` [PATCH v2 21/21] Documentation: update and rename api-sha1-array.txt brian m. carlson
2017-03-28  7:31 ` [PATCH v2 00/21] object_id part 7 Jeff King
2017-03-28 11:13   ` brian m. carlson
2017-03-28 17:35     ` Jeff King
2017-03-28 17:42       ` Jeff King
2017-03-28 19:40         ` Junio C Hamano
2017-03-28 20:00           ` Jeff King
2017-03-28 17:32   ` Junio C Hamano

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=20170326160143.769630-3-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /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).