[PATCH 1/1] rpdfs-progs: Fix binary search in find_recent_commit()

Chris Kirby <[email protected]>
Newsgroups dev.linux.lists.rpdfs-devel
Message-ID <5a7a8a1e0baf107b695128ffbe55ec05a46789eb.1786630946.git.ckirby@versity.com>
When setting the midpoint, divide by two instead of by four. This
prevents the search from looping forever when there is only a single
COMMIT at offset zero, like with a new-to-rpdfs device that was just
formatted.

Signed-off-by: Chris Kirby <[email protected]>
---
 devd/lstore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/devd/lstore.c b/devd/lstore.c
index ad1849c..5c3d0c8 100644
--- a/devd/lstore.c
+++ b/devd/lstore.c
@@ -367,7 +367,7 @@ static int lstore_blk_write(struct list_head *list)
 		goto out;
 	}
 
-	/* the first block must he a commit block, this is a pretty weak check */
+	/* the first block must be a commit block, this is a pretty weak check */
 	cmt = hnd->data;
 	if (cmt->hdr.type != RPDFS_LOG_BLOCK_TYPE_COMMIT) {
 		ret = -EINVAL;
@@ -834,7 +834,7 @@ static int find_recent_commit(struct lstore_instance *inst, u64 size, u64 *recen
 	*recent = U64_MAX;
 
 	while (start <= last) {
-		mid = (start + last) >> 2;
+		mid = (start + last) / 2;
 		dev_addr = mid << SEARCH_OFFSET_SHIFT;
 
 		hnd = lstore_read_block(dev_addr, RPDFS_LOG_BLOCK_TYPE_COMMIT, 0, NULL);
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.