From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 756B6158041 for ; Mon, 8 Apr 2024 19:27:09 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8447FE2A0A; Mon, 8 Apr 2024 19:27:08 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6941FE2A0A for ; Mon, 8 Apr 2024 19:27:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7FA743430EE for ; Mon, 8 Apr 2024 19:27:07 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DC04415DA for ; Mon, 8 Apr 2024 19:27:05 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1712604419.9594126239e0d21b88c3b8c535b6635b4a8b8892.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/xarray.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 9594126239e0d21b88c3b8c535b6635b4a8b8892 X-VCS-Branch: master Date: Mon, 8 Apr 2024 19:27:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 5e619926-87dc-40aa-b74e-c90d927a971d X-Archives-Hash: 9bc40eb94ea864d91616931da6e5728c commit: 9594126239e0d21b88c3b8c535b6635b4a8b8892 Author: Boris Staletic protonmail com> AuthorDate: Fri Mar 29 17:30:05 2024 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 8 19:26:59 2024 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=95941262 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 protonmail.com> Signed-off-by: Fabian Groffen gentoo.org> libq/xarray.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libq/xarray.c b/libq/xarray.c index 49b478b..3251a12 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 - @@ -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)