Skip to content

Commit

Permalink
bundle transport: fix an alloc_ref() call
Browse files Browse the repository at this point in the history
Currently alloc_ref() expects the length of the refname plus 1
as its parameter, prepares that much space and returns a "ref"
structure for the caller to fill the refname.  One caller in
transport.c::get_refs_from_bundle() however allocated one byte
less.

It may be a good idea to change the calling convention to give
alloc_ref() the length of the refname, but that clean-up can be
done in a separate patch.  This patch only fixes the bug and
makes all callers consistent.

There was also one overallocation in connect.c, which would not
hurt but was wasteful.  This patch fixes it as well.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Sep 30, 2007
1 parent cfb8f89 commit 90446a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ struct ref **get_remote_heads(int in, struct ref **list,
continue;
if (nr_match && !path_match(name, nr_match, match))
continue;
ref = alloc_ref(len - 40);
ref = alloc_ref(name_len + 1);
hashcpy(ref->old_sha1, old_sha1);
memcpy(ref->name, buffer + 41, len - 40);
memcpy(ref->name, buffer + 41, name_len + 1);
*list = ref;
list = &ref->next;
}
Expand Down
2 changes: 1 addition & 1 deletion transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static struct ref *get_refs_from_bundle(const struct transport *transport)
die ("Could not read bundle '%s'.", transport->url);
for (i = 0; i < data->header.references.nr; i++) {
struct ref_list_entry *e = data->header.references.list + i;
struct ref *ref = alloc_ref(strlen(e->name));
struct ref *ref = alloc_ref(strlen(e->name) + 1);
hashcpy(ref->old_sha1, e->sha1);
strcpy(ref->name, e->name);
ref->next = result;
Expand Down

0 comments on commit 90446a0

Please sign in to comment.