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

[PATCH 2/5] mailmap: Remove buffer length limit in map_user

From
Antoine Pelisse <apelisse@gmail.com>
Date
Dec 11, 2012, 22:21 UTC
Message-ID
<1355264493-8298-3-git-send-email-apelisse@gmail.com>
In-Reply-To
<1355264493-8298-1-git-send-email-apelisse@gmail.com>

Remove the hard limit set by mail buffer in map_user and use the strbuf API to replace it.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
 mailmap.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/mailmap.c b/mailmap.c
index ea4b471..e636278 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -193,7 +193,8 @@ int map_user(struct string_list *map,
 	char *end_of_email;
 	struct string_list_item *item;
 	struct mailmap_entry *me;
-	char buf[1024], *mailbuf;
+	struct strbuf buf = STRBUF_INIT;
+	char *mailbuf;
 	int i;
 
 	/* figure out space requirement for email */
@@ -204,15 +205,13 @@ int map_user(struct string_list *map,
 		if (!end_of_email)
 			return 0;
 	}
-	if (end_of_email - email + 1 < sizeof(buf))
-		mailbuf = buf;
-	else
-		mailbuf = xmalloc(end_of_email - email + 1);
 
 	/* downcase the email address */
+	strbuf_grow(&buf, end_of_email - email);
 	for (i = 0; i < end_of_email - email; i++)
-		mailbuf[i] = tolower(email[i]);
-	mailbuf[i] = 0;
+		strbuf_addch(&buf, tolower(email[i]));
+	strbuf_addch(&buf, 0);
+	mailbuf = strbuf_detach(&buf, 0);
 
 	debug_mm("map_user: map '%s' <%s>\n", name, mailbuf);
 	item = string_list_lookup(map, mailbuf);
@@ -226,8 +225,7 @@ int map_user(struct string_list *map,
 				item = subitem;
 		}
 	}
-	if (mailbuf != buf)
-		free(mailbuf);
+	free(mailbuf);
 	if (item != NULL) {
 		struct mailmap_info *mi = (struct mailmap_info *)item->util;
 		if (mi->name == NULL && (mi->email == NULL || maxlen_email == 0)) {
-- 
1.8.1.rc1.5.g7e0651a
Previous: Antoine PelisseNext: Antoine Pelisse
Message 3 of 12 in “Allow git log to use mailmap file”
  1. 0/5 Allow git log to use mailmap fileAntoine Pelisse, Dec 11, 2012
  2. 1/5 Use split_ident_line to parse author and committerAntoine Pelisse, Dec 11, 2012
  3. 2/5 mailmap: Remove buffer length limit in map_userAntoine Pelisse, Dec 11, 2012
  4. 3/5 mailmap: Add mailmap structure to rev_info and ppAntoine Pelisse, Dec 11, 2012
  5. 4/5 pretty: Use mailmap to display username and emailAntoine Pelisse, Dec 11, 2012
  6. Junio C HamanoDec 11, 2012
  7. Antoine PelisseDec 12, 2012
  8. 5/5 log: Add --use-mailmap optionAntoine Pelisse, Dec 11, 2012
  9. Antoine PelisseDec 12, 2012
  10. Junio C HamanoDec 12, 2012
  11. Junio C HamanoDec 11, 2012
  12. Rich MidwinterDec 11, 2012

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.