diff --git a/lang/cem/libcc.ansi/stdlib/qsort.c b/lang/cem/libcc.ansi/stdlib/qsort.c index 765252a31..c9b2d33c4 100644 --- a/lang/cem/libcc.ansi/stdlib/qsort.c +++ b/lang/cem/libcc.ansi/stdlib/qsort.c @@ -15,6 +15,8 @@ void qsort(void *base, size_t nel, size_t width, 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; qsort1(base, (char *)base + (nel - 1) * width, width); }