fixed qsort() for 0 elements
authoreck <none@none>
Tue, 28 Aug 1990 14:03:24 +0000 (14:03 +0000)
committereck <none@none>
Tue, 28 Aug 1990 14:03:24 +0000 (14:03 +0000)
lang/cem/libcc.ansi/stdlib/qsort.c

index 765252a..c9b2d33 100644 (file)
@@ -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);
 }