From: eck Date: Tue, 28 Aug 1990 14:03:24 +0000 (+0000) Subject: fixed qsort() for 0 elements X-Git-Tag: release-5-5~1581 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4ab420fb0f00a8d27e63b3ef71c8baf933181956;p=ack.git fixed qsort() for 0 elements --- 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); }