diff options
author | 2023-11-21 16:45:35 +0100 | |
---|---|---|
committer | 2023-11-21 16:45:47 +0100 | |
commit | e4d8117b82065dc72e8df80097360e7c05a349b9 (patch) | |
tree | 6874c1f8d0da6e199a725d03df8f1b46f7f04bef | |
parent | hurd: fix restarting reauth_dtable on signal (diff) | |
download | glibc-e4d8117b82065dc72e8df80097360e7c05a349b9.tar.xz glibc-e4d8117b82065dc72e8df80097360e7c05a349b9.zip |
stdlib: Avoid another self-comparison in qsort
In the insertion phase, we could run off the start of the array if the
comparison function never runs zero. In that case, it never finds the
initial element that terminates the iteration.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
-rw-r--r-- | stdlib/qsort.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/stdlib/qsort.c b/stdlib/qsort.c index ad110e8a89..6d0c4447ec 100644 --- a/stdlib/qsort.c +++ b/stdlib/qsort.c @@ -217,7 +217,7 @@ insertion_sort_qsort_partitions (void *const pbase, size_t total_elems, while ((run_ptr += size) <= end_ptr) { tmp_ptr = run_ptr - size; - while (cmp (run_ptr, tmp_ptr, arg) < 0) + while (run_ptr != tmp_ptr && cmp (run_ptr, tmp_ptr, arg) < 0) tmp_ptr -= size; tmp_ptr += size; |