]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Avoid passing NULL to qsort() or bsearch() on empty array.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 14 Dec 2015 15:42:34 +0000 (17:42 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 14 Dec 2015 15:42:34 +0000 (17:42 +0200)
This wouldn't normally matter because count=0 so it wouldn't be dereferenced
anyway. But it triggered a run-time warning from clang, so lets fix it.

src/lib/array.c

index acc3853299a5a3fae0d33de05d9c26b0a9e8580c..619d43cb6b2e98d6ce9278ff79c02004e2107e17 100644 (file)
@@ -124,6 +124,8 @@ void array_sort_i(struct array *array, int (*cmp)(const void *, const void *))
        unsigned int count;
 
        count = array_count_i(array);
+       if (count == 0)
+               return;
        qsort(buffer_get_modifiable_data(array->buffer, NULL),
              count, array->element_size, cmp);
 }