public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] stdlib: Fix heapsort for cases with exactly two elements Date: Tue, 16 Jan 2024 15:20:36 +0000 (GMT) [thread overview] Message-ID: <20240116152036.6E7853858D37@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=74d2731a5fb2676b64092bc25e7f193db1b17b2b commit 74d2731a5fb2676b64092bc25e7f193db1b17b2b Author: Kuan-Wei Chiu <visitorckw@gmail.com> Date: Tue Jan 16 10:16:56 2024 +0800 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> Diff: --- 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 15:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240116152036.6E7853858D37@sourceware.org \ --to=azanella@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /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: linkBe 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).