From 4ab420fb0f00a8d27e63b3ef71c8baf933181956 Mon Sep 17 00:00:00 2001 From: eck Date: Tue, 28 Aug 1990 14:03:24 +0000 Subject: [PATCH] fixed qsort() for 0 elements --- lang/cem/libcc.ansi/stdlib/qsort.c | 2 ++ 1 file changed, 2 insertions(+) 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); } -- 2.34.1