diff options
author | anlan_cs <vic.lan@pica8.com> | 2022-05-13 04:14:11 +0200 |
---|---|---|
committer | anlan_cs <vic.lan@pica8.com> | 2022-05-13 04:36:54 +0200 |
commit | 2f58dc31e80348533fdb08ef578fba49d2c30ef6 (patch) | |
tree | ae9fcbf534df8efb54485c3619ad13fa05364c63 /lib/linklist.c | |
parent | Merge pull request #11138 from opensourcerouting/fix/rpki (diff) | |
download | frr-2f58dc31e80348533fdb08ef578fba49d2c30ef6.tar.xz frr-2f58dc31e80348533fdb08ef578fba49d2c30ef6.zip |
lib: add one check in "list_sort()"
Add one check in `list_sort()`:
Immediatly return if no any items in this list.
Signed-off-by: anlan_cs <vic.lan@pica8.com>
Diffstat (limited to 'lib/linklist.c')
-rw-r--r-- | lib/linklist.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/linklist.c b/lib/linklist.c index 8137b68d8..851948288 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); |