aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/sort.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/sort.c b/lib/sort.c
index 5f3b51ffa1dc..488788b341cb 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -49,15 +49,15 @@ void sort(void *base, size_t num, size_t size,
49 void (*swap)(void *, void *, int size)) 49 void (*swap)(void *, void *, int size))
50{ 50{
51 /* pre-scale counters for performance */ 51 /* pre-scale counters for performance */
52 int i = (num/2) * size, n = num * size, c, r; 52 int i = (num/2 - 1) * size, n = num * size, c, r;
53 53
54 if (!swap) 54 if (!swap)
55 swap = (size == 4 ? u32_swap : generic_swap); 55 swap = (size == 4 ? u32_swap : generic_swap);
56 56
57 /* heapify */ 57 /* heapify */
58 for ( ; i >= 0; i -= size) { 58 for ( ; i >= 0; i -= size) {
59 for (r = i; r * 2 < n; r = c) { 59 for (r = i; r * 2 + size < n; r = c) {
60 c = r * 2; 60 c = r * 2 + size;
61 if (c < n - size && cmp(base + c, base + c + size) < 0) 61 if (c < n - size && cmp(base + c, base + c + size) < 0)
62 c += size; 62 c += size;
63 if (cmp(base + r, base + c) >= 0) 63 if (cmp(base + r, base + c) >= 0)
@@ -69,8 +69,8 @@ void sort(void *base, size_t num, size_t size,
69 /* sort */ 69 /* sort */
70 for (i = n - size; i >= 0; i -= size) { 70 for (i = n - size; i >= 0; i -= size) {
71 swap(base, base + i, size); 71 swap(base, base + i, size);
72 for (r = 0; r * 2 < i; r = c) { 72 for (r = 0; r * 2 + size < i; r = c) {
73 c = r * 2; 73 c = r * 2 + size;
74 if (c < i - size && cmp(base + c, base + c + size) < 0) 74 if (c < i - size && cmp(base + c, base + c + size) < 0)
75 c += size; 75 c += size;
76 if (cmp(base + r, base + c) >= 0) 76 if (cmp(base + r, base + c) >= 0)