aboutsummaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2006-02-12 11:24:50 -0800
committerJunio C Hamano <junkio@cox.net>2006-02-12 11:24:50 -0800
commitd7ee090d0d425606c599327c01fcbcdb60f6b090 (patch)
tree4520ebefd24e683a60a39a7e841e704049937b47 /object.c
parent2b796360acbdf3186ab9a5dcb84fe416eda4ffd5 (diff)
downloadgit-d7ee090d0d425606c599327c01fcbcdb60f6b090.tar.gz
git-d7ee090d0d425606c599327c01fcbcdb60f6b090.tar.xz
Fix object re-hashing
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) [jc: with trivial fix on trivial fix] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'object.c')
-rw-r--r--object.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/object.c b/object.c
index c3616da81..c9ca48149 100644
--- a/object.c
+++ b/object.c
@@ -60,7 +60,7 @@ void created_object(const unsigned char *sha1, struct object *obj)
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; i < obj_allocs; i++)
if (objs[i]) {
int j = find_object(objs[i]->sha1);
if (j != i) {