Browse Source

libc: qsort: bail early when sizes are 0

K. Lange 4 years ago
parent
commit
399a1f2e0c
1 changed files with 6 additions and 0 deletions
  1. 6 0
      libc/stdlib/qsort.c

+ 6 - 0
libc/stdlib/qsort.c

@@ -1,9 +1,15 @@
+#include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
 #include <sys/types.h>
 
+extern char * _argv_0;
+extern int __libc_debug;
+
 void qsort(void * base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) {
+	if (!nmemb) return;
+	if (!size) return;
 	for (size_t i = 0; i < nmemb-1; ++i) {
 		for (size_t j = 0; j < nmemb-1; ++j) {
 			void * left = (char *)base + size * j;