mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
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>
This commit is contained in:
parent
9d2703c109
commit
74d2731a5f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user