From 0cfb355e1fbd16c67366b17926a330a47e6689ce Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 29 Jun 2022 18:54:07 +0200 Subject: [PATCH] hashindex_compact: fix eval order (check idx before use), fixes #5899 also: fix "off by one" comment --- src/borg/_hashindex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/borg/_hashindex.c b/src/borg/_hashindex.c index 438c49906..bc8700e46 100644 --- a/src/borg/_hashindex.c +++ b/src/borg/_hashindex.c @@ -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; @@ -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--; }