fixed qsort() for 0 elements
This commit is contained in:
parent
bc83231874
commit
4ab420fb0f
1 changed files with 2 additions and 0 deletions
|
@ -15,6 +15,8 @@ void
|
||||||
qsort(void *base, size_t nel, size_t width,
|
qsort(void *base, size_t nel, size_t width,
|
||||||
int (*compar)(const void *, const void *))
|
int (*compar)(const void *, const void *))
|
||||||
{
|
{
|
||||||
|
/* when nel is 0, the expression '(nel - 1) * width' is wrong */
|
||||||
|
if (!nel) return;
|
||||||
qcompar = (int (*)(const char *, const char *)) compar;
|
qcompar = (int (*)(const char *, const char *)) compar;
|
||||||
qsort1(base, (char *)base + (nel - 1) * width, width);
|
qsort1(base, (char *)base + (nel - 1) * width, width);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue