git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH maint] builtin-merge.c: fix memory under-allocation
@ 2008-10-09  0:07 Brandon Casey
  2008-10-09  0:17 ` Miklos Vajna
  0 siblings, 1 reply; 7+ messages in thread
From: Brandon Casey @ 2008-10-09  0:07 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Git Mailing List

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

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---


This causes segfault on IRIX64. I guess the irix compiler doesn't
over-allocate memory as aggressively as gcc.

-brandon


 builtin-merge.c |    4 ++--
 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);
-- 
1.6.0.2.446.ge243d

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-10-09 15:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-09  0:07 [PATCH maint] builtin-merge.c: fix memory under-allocation Brandon Casey
2008-10-09  0:17 ` Miklos Vajna
2008-10-09  0:27   ` Brandon Casey
2008-10-09 11:12     ` Junio C Hamano
2008-10-09 14:15       ` Brandon Casey
2008-10-09 14:49         ` Miklos Vajna
2008-10-09 15:13         ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).