summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Casey <casey@nrlssc.navy.mil>2008-10-09 00:07:54 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2008-10-09 15:13:29 (GMT)
commit36e40535dcafe230a7f5ef43fea5cf67c1c58f6f (patch)
tree16778e960ebdeff1b627b5ae5d2221d94b955951
parentfb7424363643d6049faf3bda399e5e602782b5b7 (diff)
downloadgit-36e40535dcafe230a7f5ef43fea5cf67c1c58f6f.zip
git-36e40535dcafe230a7f5ef43fea5cf67c1c58f6f.tar.gz
git-36e40535dcafe230a7f5ef43fea5cf67c1c58f6f.tar.bz2
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>
-rw-r--r--builtin-merge.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin-merge.c b/builtin-merge.c
index dcaf368..d0bf1fc 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -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);