glibc/qsort-invalid-cmp.patch

30 lines
1.0 KiB
Diff

Index: glibc-2.38/stdlib/qsort.c
===================================================================
--- glibc-2.38.orig/stdlib/qsort.c
+++ glibc-2.38/stdlib/qsort.c
@@ -136,10 +136,12 @@ _quicksort (void *const pbase, size_t to
that this algorithm runs much faster than others. */
do
{
- while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0)
+ while (left_ptr != mid
+ && (*cmp) ((void *) left_ptr, (void *) mid, arg) < 0)
left_ptr += size;
- while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0)
+ while (right_ptr != mid
+ && (*cmp) ((void *) mid, (void *) right_ptr, arg) < 0)
right_ptr -= size;
if (left_ptr < right_ptr)
@@ -224,7 +226,8 @@ _quicksort (void *const pbase, size_t to
while ((run_ptr += size) <= end_ptr)
{
tmp_ptr = run_ptr - size;
- while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0)
+ while (tmp_ptr != base_ptr
+ && (*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0)
tmp_ptr -= size;
tmp_ptr += size;