Skip to content

Commit

Permalink
builtin-merge.c: allocate correct amount of memory
Browse files Browse the repository at this point in the history
Fix two memory allocation errors which allocate space for a pointer
rather than enough space for the structure itself.

This:

    struct commit_list *parent = xmalloc(sizeof(struct commit_list *));

should have been this:

    struct commit_list *parent = xmalloc(sizeof(struct commit_list));

But while we're at it, change the allocation to reference the
variable it is allocating memory for to try to prevent a similar
mistake, for example if the type is changed, in the future.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Acked-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Brandon Casey authored and Shawn O. Pearce committed Oct 9, 2008
1 parent fb74243 commit 36e4053
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,12 @@ static void add_strategies(const char *string, unsigned attr)
static int merge_trivial(void)
{
unsigned char result_tree[20], result_commit[20];
struct commit_list *parent = xmalloc(sizeof(struct commit_list *));
struct commit_list *parent = xmalloc(sizeof(*parent));

write_tree_trivial(result_tree);
printf("Wonderful.\n");
parent->item = lookup_commit(head);
parent->next = xmalloc(sizeof(struct commit_list *));
parent->next = xmalloc(sizeof(*parent->next));
parent->next->item = remoteheads->item;
parent->next->next = NULL;
commit_tree(merge_msg.buf, result_tree, parent, result_commit);
Expand Down

0 comments on commit 36e4053

Please sign in to comment.