From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>,
Git Mailing List <git@vger.kernel.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Fix object re-hashing
Date: Sun, 12 Feb 2006 10:04:26 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0602120956130.3691@g5.osdl.org> (raw)
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) {
next reply other threads:[~2006-02-12 18:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-12 18:04 Linus Torvalds [this message]
2006-02-12 18:10 ` Fix object re-hashing 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0602120956130.3691@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).