about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
authorKuan-Wei Chiu <visitorckw@gmail.com>2024-01-16 10:16:56 +0800
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-01-16 11:00:51 -0300
commit74d2731a5fb2676b64092bc25e7f193db1b17b2b (patch)
tree228624cbc2f6b113d815de83ea0c5a9cbc883364 /stdlib
parent9d2703c109791d1ff0bf1f611b0b78f1703f51eb (diff)
downloadglibc-74d2731a5fb2676b64092bc25e7f193db1b17b2b.tar.gz
glibc-74d2731a5fb2676b64092bc25e7f193db1b17b2b.tar.xz
glibc-74d2731a5fb2676b64092bc25e7f193db1b17b2b.zip
stdlib: Fix heapsort for cases with exactly two elements
When malloc fails to allocate a buffer and falls back to heapsort, the
current heapsort implementation does not perform sorting when there are
exactly two elements. Heapsort is now skipped only when there is
exactly one element.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/qsort.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/stdlib/qsort.c b/stdlib/qsort.c
index b29882388e..45af8da80c 100644
--- a/stdlib/qsort.c
+++ b/stdlib/qsort.c
@@ -162,7 +162,7 @@ get_swap_type (void *const pbase, size_t size)
 static void
 heapsort_r (void *base, size_t n, size_t size, __compar_d_fn_t cmp, void *arg)
 {
-  if (n <= 1)
+  if (n == 0)
     return;
 
   enum swap_type_t swap_type = get_swap_type (base, size);