1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-03 10:17:40 +00:00

Fix hashindex_lookup corner case (infinite loop)

This commit is contained in:
Jonas Borgström 2010-12-29 20:18:22 +01:00
parent 666db4bf4f
commit 0e3ba200b1

View file

@ -44,19 +44,19 @@ static int
hashindex_lookup(HashIndex *index, const void *key)
{
int didx = -1;
int idx = hashindex_index(index, key);
int start = hashindex_index(index, key);
int idx = start;
for(;;) {
while(BUCKET_IS_DELETED(index, idx)) {
if(didx == -1) {
didx = idx;
}
idx = (idx + 1) % index->num_buckets;
}
if(BUCKET_IS_EMPTY(index, idx))
{
return -1;
}
if(BUCKET_MATCHES_KEY(index, idx, key)) {
if(BUCKET_IS_DELETED(index, idx)) {
if(didx == -1) {
didx = idx;
}
}
else if(BUCKET_MATCHES_KEY(index, idx, key)) {
if (didx != -1) {
memcpy(BUCKET_ADDR(index, didx), BUCKET_ADDR(index, idx), index->bucket_size);
BUCKET_MARK_DELETED(index, idx);
@ -65,6 +65,9 @@ hashindex_lookup(HashIndex *index, const void *key)
return idx;
}
idx = (idx + 1) % index->num_buckets;
if(idx == start) {
return -1;
}
}
}