This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/19305] New: qsort() should return early if (nmemb <= 1)


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]