From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 4E9A23858407; Tue, 21 Nov 2023 16:10:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E9A23858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1700583001; bh=cKKquSBdi9GBK6LfkXD6iCIOZfebXUh3m986/gdbWJo=; h=From:To:Subject:Date:From; b=T30Eaeob6EfTusTIlt4eCDveNWJJqv016wXIoqebBpW7gCVP4DFofgPPJ1P9IVjQU UZ5ybd96l/NKEZOm4kqWhsjCg0Knlc6yY5wikAdtYSI2NvMRfEZo76gyNsPRiM3/OD oNbbNUGrPvsW8fRKcLM0qj1v/urCMXaYylYLV6Dg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] stdlib: Avoid another self-comparison in qsort X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/master X-Git-Oldrev: dd858522bf36ae16496ea01ff8b65e16b4e5c22b X-Git-Newrev: e4d8117b82065dc72e8df80097360e7c05a349b9 Message-Id: <20231121161001.4E9A23858407@sourceware.org> Date: Tue, 21 Nov 2023 16:10:01 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e4d8117b82065dc72e8df80097360e7c05a349b9 commit e4d8117b82065dc72e8df80097360e7c05a349b9 Author: Florian Weimer Date: Tue Nov 21 16:45:35 2023 +0100 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 Diff: --- stdlib/qsort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;