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

Re: [RFH] index_name_exists() conversion

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 21, 2008, 17:00 UTC
Message-ID
<alpine.LFD.1.00.0802210816380.7833@woody.linux-foundation.org>
In-Reply-To
<alpine.LFD.1.00.0802210806540.7833@woody.linux-foundation.org>
On Thu, 21 Feb 2008, Linus Torvalds wrote:
> 
> (Also, some code used to just reuse the same cache entry multiple times, 
> and that got illegal for the same reason).
Ahh. I think I may have found it.
It's stupid.

In hash_index_entry(), we insert the entry into the name hash, but if it got inserted as the first entry, we don't actually set the ->next pointer to NULL.

So the chain would end up pointing to some random crud. I think we were just lucky with our allocators generally filling those things with zero.

See if this fixes it.
		Linus
---
diff --git a/read-cache.c b/read-cache.c
--- a/read-cache.c
+++ b/read-cache.c
@@ -39,6 +39,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
 	void **pos;
 	unsigned int hash = hash_name(ce->name, ce_namelen(ce));
 
+	ce->next = NULL;
 	pos = insert_hash(hash, ce, &istate->name_hash);
 	if (pos) {
 		ce->next = *pos;
Previous: Johannes SchindelinNext: Linus Torvalds
Message 5 of 10 in “[RFH] CE_REMOVE conversion”
  1. Junio C HamanoFeb 21, 2008
  2. [RFH] index_name_exists() conversionJunio C Hamano, Feb 21, 2008
  3. Linus TorvaldsFeb 21, 2008
  4. Johannes SchindelinFeb 21, 2008
  5. Linus TorvaldsFeb 21, 2008
  6. Linus TorvaldsFeb 21, 2008
  7. Junio C HamanoFeb 21, 2008
  8. Linus TorvaldsFeb 21, 2008
  9. Linus TorvaldsFeb 21, 2008
  10. Junio C HamanoFeb 21, 2008

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.