diff options
author | 2024-03-29 18:30:05 +0100 | |
---|---|---|
committer | 2024-04-08 21:26:59 +0200 | |
commit | 9594126239e0d21b88c3b8c535b6635b4a8b8892 (patch) | |
tree | c7fea74ab5b3cca354fda7b61798a0d40bd71b35 | |
parent | tests: Avoid buffer underflow when checking rmspace result (diff) | |
download | portage-utils-9594126239e0d21b88c3b8c535b6635b4a8b8892.tar.gz portage-utils-9594126239e0d21b88c3b8c535b6635b4a8b8892.tar.bz2 portage-utils-9594126239e0d21b88c3b8c535b6635b4a8b8892.zip |
libq/xarray: Handle NULL arrays in xarraysort()
Some invocations of `q` may try to call `xarraysort(NULL, 0)`.
One example is `qlop -a foo` where `foo` was never unmerged.
Instead of requiring every call of `xarraysort()` to take care of `NULL`
arguments, `xarraysort()` now exits early if `arr->eles == NULL`.
Closes: https://github.com/gentoo/portage-utils/pull/28
Signed-off-by: Boris Staletic <boris.staletic@protonmail.com>
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r-- | libq/xarray.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libq/xarray.c b/libq/xarray.c index 49b478be..3251a124 100644 --- a/libq/xarray.c +++ b/libq/xarray.c @@ -1,5 +1,5 @@ /* - * Copyright 2003-2019 Gentoo Foundation + * Copyright 2003-2024 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> @@ -46,7 +46,8 @@ void *xarraypush(array_t *arr, const void *ele, size_t ele_len) void xarraysort(array_t *arr, int (*compar)(const void *, const void *)) { - qsort(arr->eles, arr->num, sizeof(void *), compar); + if (arr->num > 1) + qsort(arr->eles, arr->num, sizeof(void *), compar); } void xarraydelete_ptr(array_t *arr, size_t elem) |