git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: problem in unpack-trees.c

From
Junio C Hamano <junkio@cox.net>
Date
Dec 4, 2006, 10:00 UTC
Message-ID
<7vhcwcq8u7.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vodqkq956.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
> If the alignment requirement of the platform is smaller, we may
> be overstepping the struct when we access its name[] member.
Would this help?

I do not think we need a separate identity for df_conflict_entry per invocation of unpack_trees(), so this allocates one such entry with NUL name at the first call to the function and reuses it from the variable.

diff --git a/unpack-trees.c b/unpack-trees.c
index 7cfd628..47aa804 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -370,7 +370,7 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
 	int i;
 	struct object_list *posn = trees;
 	struct tree_entry_list df_conflict_list;
-	struct cache_entry df_conflict_entry;
+	static struct cache_entry *dfc;
 
 	memset(&df_conflict_list, 0, sizeof(df_conflict_list));
 	df_conflict_list.next = &df_conflict_list;
@@ -381,8 +381,10 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
 	state.refresh_cache = 1;
 
 	o->merge_size = len;
-	memset(&df_conflict_entry, 0, sizeof(df_conflict_entry));
-	o->df_conflict_entry = &df_conflict_entry;
+
+	if (!dfc)
+		dfc = xcalloc(1, sizeof(struct cache_entry) + 1);
+	o->df_conflict_entry = dfc;
 
 	if (len) {
 		posns = xmalloc(len * sizeof(struct tree_entry_list *));
Previous: Junio C HamanoNext: Roman Zippel
Message 3 of 4 in “problem in unpack-trees.c”
  1. Roman ZippelDec 3, 2006
  2. Junio C HamanoDec 4, 2006
  3. Junio C HamanoDec 4, 2006
  4. Roman ZippelDec 4, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.