diff options
author | Alexander Barkov <bar@mnogosearch.org> | 2013-11-08 22:19:24 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mnogosearch.org> | 2013-11-08 22:19:24 +0400 |
commit | a4dc526fc7b33891b6d79d36c5abc198c89a53c8 (patch) | |
tree | 74556e7cfc9f0fb5ba17e2ea3cb763f5d29f10be | |
parent | 11d141004af2507cd15751bad7378851a9347527 (diff) | |
download | mariadb-git-a4dc526fc7b33891b6d79d36c5abc198c89a53c8.tar.gz |
MDEV-5181 incorrect binary search in remove_status_vars()
The loop in the binary search in remove_status_vars() was
incorrectly implemented and could continue infinitely in some cases.
Rewrote the binary search code.
-rw-r--r-- | sql/sql_show.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6193085e110..18818ed5e11 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2202,19 +2202,20 @@ void remove_status_vars(SHOW_VAR *list) for (; list->name; list++) { - int res= 0, a= 0, b= all_status_vars.elements, c= (a+b)/2; - for (; b-a > 0; c= (a+b)/2) + int first= 0, last= ((int) all_status_vars.elements) - 1; + for ( ; first <= last; ) { - res= show_var_cmp(list, all+c); - if (res < 0) - b= c; + int res, middle= (first + last) / 2; + if ((res= show_var_cmp(list, all + middle)) < 0) + last= middle - 1; else if (res > 0) - a= c; + first= middle + 1; else + { + all[middle].type= SHOW_UNDEF; break; + } } - if (res == 0) - all[c].type= SHOW_UNDEF; } shrink_var_array(&all_status_vars); pthread_mutex_unlock(&LOCK_status); |