Skip to content

Commit

Permalink
Merge pull request #6817 from ThomasWaldmann/fix-hashindex-compact-1.1
Browse files Browse the repository at this point in the history
hashindex_compact: fix eval order (check idx before use), fixes #5899
  • Loading branch information
ThomasWaldmann committed Jun 30, 2022
2 parents 53b6d14 + 0cfb355 commit 7a29c11
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/borg/_hashindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,11 @@ hashindex_compact(HashIndex *index)
while(idx < index->num_buckets) {
/* Phase 1: Find some empty slots */
start_idx = idx;
while((BUCKET_IS_EMPTY(index, idx) || BUCKET_IS_DELETED(index, idx)) && idx < index->num_buckets) {
while((idx < index->num_buckets) && (BUCKET_IS_EMPTY(index, idx) || BUCKET_IS_DELETED(index, idx))) {
idx++;
}

/* everything from start_idx to idx is empty or deleted */
/* everything from start_idx to idx-1 (inclusive) is empty or deleted */
count = empty_slot_count = idx - start_idx;
begin_used_idx = idx;

Expand All @@ -658,7 +658,7 @@ hashindex_compact(HashIndex *index)

/* Phase 2: Find some non-empty/non-deleted slots we can move to the compact tail */

while(!(BUCKET_IS_EMPTY(index, idx) || BUCKET_IS_DELETED(index, idx)) && empty_slot_count && idx < index->num_buckets) {
while(empty_slot_count && (idx < index->num_buckets) && !(BUCKET_IS_EMPTY(index, idx) || BUCKET_IS_DELETED(index, idx))) {
idx++;
empty_slot_count--;
}
Expand Down

0 comments on commit 7a29c11

Please sign in to comment.