Skip to content

Commit

Permalink
fmt-merge-msg: don't use static buffer in record_person
Browse files Browse the repository at this point in the history
The record_person function just parses out the "name" field
of the person line in a commit and adds it to a string_list.
The only reason we need an extra buffer is that the
string_list functions require a NUL-terminated string.

Instead of the static buffer, we can just allocate a
temporary NUL-terminated copy. In addition to removing a
useless limit, this removes the only user of MAX_GITNAME
outside of ident.c.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 22, 2012
1 parent 5cb2194 commit e21ab13
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin/fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)
static void record_person(int which, struct string_list *people,
struct commit *commit)
{
char name_buf[MAX_GITNAME], *name, *name_end;
char *name_buf, *name, *name_end;
struct string_list_item *elem;
const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";

Expand All @@ -243,17 +243,17 @@ static void record_person(int which, struct string_list *people,
name_end--;
while (isspace(*name_end) && name <= name_end)
name_end--;
if (name_end < name || name + MAX_GITNAME <= name_end)
if (name_end < name)
return;
memcpy(name_buf, name, name_end - name + 1);
name_buf[name_end - name + 1] = '\0';
name_buf = xmemdupz(name, name_end - name + 1);

elem = string_list_lookup(people, name_buf);
if (!elem) {
elem = string_list_insert(people, name_buf);
elem->util = (void *)0;
}
elem->util = (void*)(util_as_integral(elem) + 1);
free(name_buf);
}

static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
Expand Down

0 comments on commit e21ab13

Please sign in to comment.