Don't qsort() NULL.
authorEmil Mikulic <emikulic@gmail.com>
Sat, 15 Jan 2011 09:38:31 +0000 (20:38 +1100)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 10:37:08 +0000 (20:37 +1000)
Found by: clang static analyzer

darkhttpd.c

index f394640..b23871e 100644 (file)
@@ -1512,7 +1512,9 @@ static ssize_t make_sorted_dirlist(const char *path, struct dlent ***output) {
     }
     closedir(dir);
     free(currname);
-    qsort(list, entries, sizeof(struct dlent*), dlent_cmp);
+    assert(list != NULL);
+    if (list) /* there's gotta be at least ".." */
+        qsort(list, entries, sizeof(struct dlent*), dlent_cmp);
     *output = xrealloc(list, sizeof(struct dlent*) * entries);
     return (ssize_t)entries;
     #undef POOL_INCR