summaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-29 11:14:55 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-29 11:14:55 -0400
commit1477a3be62746765d7f93c4c7b0f7948a1541fd3 (patch)
tree3badfed4ab5c333c896fdebdfc8930f2da4b80c9 /src/stdlib
parentdef0af189871a499efdc9bc37438d8b20eb702ab (diff)
downloadmusl-1477a3be62746765d7f93c4c7b0f7948a1541fd3.tar.gz
musl-1477a3be62746765d7f93c4c7b0f7948a1541fd3.tar.bz2
musl-1477a3be62746765d7f93c4c7b0f7948a1541fd3.tar.xz
musl-1477a3be62746765d7f93c4c7b0f7948a1541fd3.zip
avoid crashing when nel==0 is passed to qsort
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/qsort.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c
index 866af0ec..434d9350 100644
--- a/src/stdlib/qsort.c
+++ b/src/stdlib/qsort.c
@@ -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 i, size = width * nel;
- unsigned char *head = base,
- *high = head + size - width;
+ unsigned char *head, *high;
size_t p[2] = {1, 0};
int pshift = 1;
int trail;
+ if (!size) return;
+
+ head = base;
+ high = head + size - 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++);