Reapply possible bsearch overflow fix Originally introduced in 21ede86 (#1314) but as it wasn't applied to hb_bsearch accidentally removed while merging hb_bsearch_r to it.