This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/19305] New: qsort() should return early if (nmemb <= 1)
- From: "fabian at greffrath dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 30 Nov 2015 06:20:26 +0000
- Subject: [Bug libc/19305] New: qsort() should return early if (nmemb <= 1)
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=19305
Bug ID: 19305
Summary: qsort() should return early if (nmemb <= 1)
Product: glibc
Version: unspecified
Status: NEW
Severity: minor
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: fabian at greffrath dot com
CC: drepper.fsp at gmail dot com
Target Milestone: ---
Hi there,
it doesn't make sense to call qsort() on an array that only contains 1 or 0
elements. There are some checks for small n, s and n*s in __qsort_r, but none
covers the trivial cases -- memory is always allocated.
Thus, I'd like to suggest to add the following trivial change to
stdlib/msort.c:308:
void
qsort (void *b, size_t n, size_t s, __compar_fn_t cmp)
{
if (n > 1)
return __qsort_r (b, n, s, (__compar_d_fn_t) cmp, NULL);
}
Thanks,
Fabian
--
You are receiving this mail because:
You are on the CC list for the bug.