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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 40E4B138334 for ; Fri, 12 Jul 2019 18:04:56 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7EE09E07A5; Fri, 12 Jul 2019 18:04:55 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6424AE07A7 for ; Fri, 12 Jul 2019 18:04:55 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 446B4347849 for ; Fri, 12 Jul 2019 18:04:54 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A41896E9 for ; Fri, 12 Jul 2019 18:04:52 +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: <1562954360.c720262bfd9a31512b03f2e3129839886d9d27c6.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: c720262bfd9a31512b03f2e3129839886d9d27c6 X-VCS-Branch: master Date: Fri, 12 Jul 2019 18:04:52 +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: 48a12591-ac3a-4107-a3ce-35d205452b8a X-Archives-Hash: 30e7b03088382d0a0ab5d6306297dce2 commit: c720262bfd9a31512b03f2e3129839886d9d27c6 Author: Fabian Groffen gentoo org> AuthorDate: Fri Jul 12 17:59:20 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Fri Jul 12 17:59:20 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c720262b libq/tree: avoid calling qsort with empty set Encountering an empty directory in tree_next_pkg_int will not populate cat_ctx->pkg_ctxs, so avoid calling qsort with it. While at it, avoid calling it for a single entry too. Bug: https://bugs.gentoo.org/689290#c7 Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libq/tree.c b/libq/tree.c index 9dfbe7d..6bb6a89 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -341,7 +341,6 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) if (cat_ctx->ctx->do_sort) { if (cat_ctx->pkg_ctxs == NULL) { size_t pkg_size = 0; - cat_ctx->pkg_ctxs = NULL; cat_ctx->pkg_cnt = 0; cat_ctx->pkg_cur = 0; while ((de = readdir(cat_ctx->dir)) != NULL) { @@ -359,7 +358,7 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx) cat_ctx->pkg_cnt--; } - if (cat_ctx->ctx->pkgsortfunc != NULL) { + if (cat_ctx->ctx->pkgsortfunc != NULL && cat_ctx->pkg_cnt > 1) { qsort(cat_ctx->pkg_ctxs, cat_ctx->pkg_cnt, sizeof(*cat_ctx->pkg_ctxs), cat_ctx->ctx->pkgsortfunc); }