oops, crash if searching for something smaller than * in the array
Dana Jansens danakj@orodu.net
1 files changed,
2 insertions(+),
1 deletions(-)
jump to
M
obt/bsearch.h
→
obt/bsearch.h
@@ -40,8 +40,9 @@ out_BSEARCH = l_BSEARCH + (r_BSEARCH - l_BSEARCH)/2; \
if ((val) == (ar)[out_BSEARCH]) { \ break; \ } \ - else if ((val) < (ar)[out_BSEARCH]) \ + else if ((val) < (ar)[out_BSEARCH] && out_BSEARCH > 0) { \ r_BSEARCH = out_BSEARCH-1; /* search to the left side */ \ + } \ else \ l_BSEARCH = out_BSEARCH+1; /* search to the left side */ \ } \