mirror of git://git.musl-libc.org/musl
avoid crashing when nel==0 is passed to qsort
This commit is contained in:
parent
def0af1898
commit
1477a3be62
|
@ -155,12 +155,16 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
|
||||||
{
|
{
|
||||||
size_t lp[12*sizeof(size_t)];
|
size_t lp[12*sizeof(size_t)];
|
||||||
size_t i, size = width * nel;
|
size_t i, size = width * nel;
|
||||||
unsigned char *head = base,
|
unsigned char *head, *high;
|
||||||
*high = head + size - width;
|
|
||||||
size_t p[2] = {1, 0};
|
size_t p[2] = {1, 0};
|
||||||
int pshift = 1;
|
int pshift = 1;
|
||||||
int trail;
|
int trail;
|
||||||
|
|
||||||
|
if (!size) return;
|
||||||
|
|
||||||
|
head = base;
|
||||||
|
high = head + size - width;
|
||||||
|
|
||||||
/* Precompute Leonardo numbers, scaled by element width */
|
/* Precompute Leonardo numbers, scaled by element width */
|
||||||
for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++);
|
for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue