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

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

From
Antoine Pelisse <apelisse@gmail.com>
Date
Dec 15, 2012, 18:05 UTC
Message-ID
<1355594754-27589-3-git-send-email-apelisse@gmail.com>
In-Reply-To
<1355594754-27589-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 |   17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/mailmap.c b/mailmap.c
index ea4b471..3bc6491 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -193,7 +193,7 @@ 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 mailbuf = STRBUF_INIT;
 	int i;
 
 	/* figure out space requirement for email */
@@ -204,18 +204,14 @@ 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(&mailbuf, end_of_email - email);
 	for (i = 0; i < end_of_email - email; i++)
-		mailbuf[i] = tolower(email[i]);
-	mailbuf[i] = 0;
+		strbuf_addch(&mailbuf, tolower(email[i]));
 
-	debug_mm("map_user: map '%s' <%s>\n", name, mailbuf);
-	item = string_list_lookup(map, mailbuf);
+	debug_mm("map_user: map '%s' <%s>\n", name, mailbuf.buf);
+	item = string_list_lookup(map, mailbuf.buf);
 	if (item != NULL) {
 		me = (struct mailmap_entry *)item->util;
 		if (me->namemap.nr) {
@@ -226,8 +222,7 @@ int map_user(struct string_list *map,
 				item = subitem;
 		}
 	}
-	if (mailbuf != buf)
-		free(mailbuf);
+	strbuf_release(&mailbuf);
 	if (item != NULL) {
 		struct mailmap_info *mi = (struct mailmap_info *)item->util;
 		if (mi->name == NULL && (mi->email == NULL || maxlen_email == 0)) {
-- 
1.7.9.5
Previous: Antoine PelisseNext: Antoine Pelisse
Message 3 of 9 in “Allow git log to use mailmap file”
  1. 0/7 Allow git log to use mailmap fileAntoine Pelisse, Dec 15, 2012
  2. 1/7 Use split_ident_line to parse author and committerAntoine Pelisse, Dec 15, 2012
  3. 2/7 mailmap: Remove buffer length limit in map_userAntoine Pelisse, Dec 15, 2012
  4. 3/7 mailmap: Simplify map_user() interfaceAntoine Pelisse, Dec 15, 2012
  5. 4/7 mailmap: Add mailmap structure to rev_info and ppAntoine Pelisse, Dec 15, 2012
  6. 5/7 pretty: Use mailmap to display username and emailAntoine Pelisse, Dec 15, 2012
  7. 6/7 log: Add --use-mailmap optionAntoine Pelisse, Dec 15, 2012
  8. 7/7 test: Add test for --use-mailmap optionAntoine Pelisse, Dec 15, 2012
  9. Junio C HamanoDec 15, 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.