summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/linklist.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/linklist.c b/lib/linklist.c
index 8137b68d84..8519482885 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -370,10 +370,15 @@ void list_sort(struct list *list, int (*cmp)(const void **, const void **))
int i = -1;
void *data;
size_t n = list->count;
- void **items = XCALLOC(MTYPE_TMP, (sizeof(void *)) * n);
+ void **items;
int (*realcmp)(const void *, const void *) =
(int (*)(const void *, const void *))cmp;
+ if (!n)
+ return;
+
+ items = XCALLOC(MTYPE_TMP, (sizeof(void *)) * n);
+
for (ALL_LIST_ELEMENTS(list, ln, nn, data)) {
items[++i] = data;
list_delete_node(list, ln);