reftable/block: fix error handling when searching restart points
When doing the binary search over restart points in a block we need to decode the record keys. This decoding step can result in an error when the block is corrupted, which we indicate to the caller of the binary search by setting `args.error = 1`. But the only caller that exists mishandles this because it in fact performs the error check before calling `binsearch()`. Fix this bug by checking for errors at the right point in time. Furthermore, refactor `binsearch()` so that it aborts the search in case the callback function returns a negative value so that we don't needlessly continue to search the block. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
77307a61d6
commit
f9e88544f5
@ -39,8 +39,11 @@ size_t binsearch(size_t sz, int (*f)(size_t k, void *args), void *args)
|
||||
*/
|
||||
while (hi - lo > 1) {
|
||||
size_t mid = lo + (hi - lo) / 2;
|
||||
int ret = f(mid, args);
|
||||
if (ret < 0)
|
||||
return sz;
|
||||
|
||||
if (f(mid, args))
|
||||
if (ret > 0)
|
||||
hi = mid;
|
||||
else
|
||||
lo = mid;
|
||||
|
Reference in New Issue
Block a user