public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Kuan-Wei Chiu <visitorckw@gmail.com>, libc-alpha@sourceware.org
Cc: fweimer@redhat.com
Subject: Re: [PATCH 1/2] stdlib: Fix heapsort for cases with exactly two elements
Date: Tue, 16 Jan 2024 07:46:45 -0300	[thread overview]
Message-ID: <2851d0b8-b6e6-49c6-81cf-6ad4c75eb5a3@linaro.org> (raw)
In-Reply-To: <20240116021657.2553198-2-visitorckw@gmail.com>



On 15/01/24 23:16, Kuan-Wei Chiu wrote:
> 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>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  stdlib/qsort.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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);

  reply	other threads:[~2024-01-16 10:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  2:16 [PATCH 0/2] stdlib: Fix and verify heapsort for two-element cases Kuan-Wei Chiu
2024-01-16  2:16 ` [PATCH 1/2] stdlib: Fix heapsort for cases with exactly two elements Kuan-Wei Chiu
2024-01-16 10:46   ` Adhemerval Zanella Netto [this message]
2024-01-16  2:16 ` [PATCH 2/2] stdlib: Verify heapsort for two-element cases Kuan-Wei Chiu
2024-01-16 10:47   ` Adhemerval Zanella Netto
2024-01-17 20:06 ` [PATCH 0/2] stdlib: Fix and verify " Andreas K. Huettel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2851d0b8-b6e6-49c6-81cf-6ad4c75eb5a3@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=visitorckw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).