From e90b17a854b8fec924fff7f6544a06aa30c87467 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 6 Jun 2008 21:01:51 +0000 Subject: [PATCH] Fix logic bug in quick sort routine. This would result in infinite recursion such as that in bug #2343. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25831 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/OutlineListView.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/kits/interface/OutlineListView.cpp b/src/kits/interface/OutlineListView.cpp index 34d71faae3..a0894630cf 100644 --- a/src/kits/interface/OutlineListView.cpp +++ b/src/kits/interface/OutlineListView.cpp @@ -27,6 +27,9 @@ static void quick_sort_item_array(BListItem** items, int32 first, int32 last, int (*compareFunc)(const BListItem* a, const BListItem* b)) { + printf("quick_sort_item_array(items: %p, first: %ld, last: %ld, comparefunc: %p)\n", + items, first, last, compareFunc); + if (last <= first) return; @@ -42,7 +45,6 @@ quick_sort_item_array(BListItem** items, int32 first, int32 last, while ((compareFunc(items[right], pivot) > 0) && (right > first)) right--; - if (left < right) { // swap entries @@ -61,13 +63,13 @@ quick_sort_item_array(BListItem** items, int32 first, int32 last, // At this point, the elements in the left half are all smaller // than the elements in the right half - if (first < right) { + if (first < left) { // sort left half - quick_sort_item_array(items, first, right, compareFunc); + quick_sort_item_array(items, first, left, compareFunc); } - if (left < last) { + if (right < last) { // sort right half - quick_sort_item_array(items, left, last, compareFunc); + quick_sort_item_array(items, right, last, compareFunc); } }