Skip to content

Commit 36e4053

Browse files
drafnelspearce
authored andcommitted
builtin-merge.c: allocate correct amount of memory
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 <[email protected]> Acked-by: Miklos Vajna <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent fb74243 commit 36e4053

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

builtin-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,12 @@ static void add_strategies(const char *string, unsigned attr)
651651
static int merge_trivial(void)
652652
{
653653
unsigned char result_tree[20], result_commit[20];
654-
struct commit_list *parent = xmalloc(sizeof(struct commit_list *));
654+
struct commit_list *parent = xmalloc(sizeof(*parent));
655655

656656
write_tree_trivial(result_tree);
657657
printf("Wonderful.\n");
658658
parent->item = lookup_commit(head);
659-
parent->next = xmalloc(sizeof(struct commit_list *));
659+
parent->next = xmalloc(sizeof(*parent->next));
660660
parent->next->item = remoteheads->item;
661661
parent->next->next = NULL;
662662
commit_tree(merge_msg.buf, result_tree, parent, result_commit);

0 commit comments

Comments
 (0)