@matheusbsbs / matheus-bagliano / commits / 36e40535dc
Fork 0

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 <casey@nrlssc.navy.mil> Acked-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Brandon Casey committed Oct 8, 2008 at 19:07 UTC 36e40535dcafe230a7f5ef43fea5cf67c1c58f6f
1 file changed +2 -2
builtin-merge.c
+2 -2
@@ -651,12 +651,12 @@ static void add_strategies(const char *string, unsigned attr)
651 static int merge_trivial(void)
652 {
653 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));
655
656 write_tree_trivial(result_tree);
657 printf("Wonderful.\n");
658 parent->item = lookup_commit(head);
659 - parent->next = xmalloc(sizeof(struct commit_list *));
659 + parent->next = xmalloc(sizeof(*parent->next));
660 parent->next->item = remoteheads->item;
661 parent->next->next = NULL;
662 commit_tree(merge_msg.buf, result_tree, parent, result_commit);