git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Fix object re-hashing
@ 2006-02-12 18:04 Linus Torvalds
  2006-02-12 18:10 ` Linus Torvalds
  2006-02-12 18:16 ` Linus Torvalds
  0 siblings, 2 replies; 13+ messages in thread
From: Linus Torvalds @ 2006-02-12 18:04 UTC (permalink / raw)
  To: Junio C Hamano, Git Mailing List, Johannes Schindelin


The hashed object lookup had a subtle bug in re-hashing: it did

	for (i = 0; i < count; i++)
		if (objs[i]) {
			.. rehash ..

where "count" was the old hash couny. Oon the face of it is obvious, since 
it clearly re-hashes all the old objects.

However, it's wrong.

If the last old hash entry before re-hashing was in use (or became in use 
by the re-hashing), then when re-hashing could have inserted an object 
into the hash entries with idx >= count due to overflow. When we then 
rehash the last old entry, that old entry might become empty, which means 
that the overflow entries should be re-hashed again.

In other words, the loop has to be fixed to either traverse the whole 
array, rather than just the old count.

(There's room for a slight optimization: instead of counting all the way 
up, we can break when we see the first empty slot that is above the old 
"count". At that point we know we don't have any collissions that we might 
have to fix up any more. This patch only does the trivial fix)

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

I actually didn't see any of this trigger in real life, so maybe my 
analysis is wrong. Junio? Johannes?

diff --git a/object.c b/object.c
index 59e5e36..aeda228 100644
--- a/object.c
+++ b/object.c
@@ -65,7 +65,7 @@ void created_object(const unsigned char 
 		objs = xrealloc(objs, obj_allocs * sizeof(struct object *));
 		memset(objs + count, 0, (obj_allocs - count)
 				* sizeof(struct object *));
-		for (i = 0; i < count; i++)
+		for (i = 0; obj_allocs ; i++)
 			if (objs[i]) {
 				int j = find_object(objs[i]->sha1);
 				if (j != i) {

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

end of thread, other threads:[~2006-02-13  0:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-12 18:04 Fix object re-hashing Linus Torvalds
2006-02-12 18:10 ` Linus Torvalds
2006-02-12 18:32   ` Junio C Hamano
2006-02-12 18:53     ` Linus Torvalds
2006-02-12 19:10       ` Linus Torvalds
2006-02-12 19:21         ` Junio C Hamano
2006-02-12 19:39           ` Linus Torvalds
2006-02-12 23:55         ` Johannes Schindelin
2006-02-13  0:16           ` Linus Torvalds
2006-02-13  0:31             ` Johannes Schindelin
2006-02-12 19:13       ` Junio C Hamano
2006-02-12 18:16 ` Linus Torvalds
2006-02-12 18:18   ` Linus Torvalds

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).