projects
/
oweals
/
musl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
def0af1
)
avoid crashing when nel==0 is passed to qsort
author
Rich Felker
<dalias@aerifal.cx>
Fri, 29 Apr 2011 15:14:55 +0000
(11:14 -0400)
committer
Rich Felker
<dalias@aerifal.cx>
Fri, 29 Apr 2011 15:14:55 +0000
(11:14 -0400)
src/stdlib/qsort.c
patch
|
blob
|
history
diff --git
a/src/stdlib/qsort.c
b/src/stdlib/qsort.c
index 866af0ecd6c2a394f896a8e3d8a0403e9da94577..434d9350726df8413295db92846d37ac7f63a2f4 100644
(file)
--- 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++);