From nobody Wed Oct 07 15:25:31 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j0H4q63Bxz6w3rd for ; Wed, 07 Oct 2026 15:25:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j0H4q5Kd0z4NRT for ; Wed, 07 Oct 2026 15:25:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791386731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjiZY7t16375uszfCoNb2V1RFbqpvI2Ni3X40g3LQCM=; b=GT24LEyGqTpyDRme9ysUkoDSHeu3Y+tuNDvIGwVkem3LeHuQ7hwJmgLLQl8BBms2OnlC4z UfQv9dcgwpDg601AGfu1OkOg0dG30MWnI5GbcHBQYDLqZfibrutjKoo/5qiMwYx7mgbPuv bOyOFGgUSxpgjG93ELMYKx8SF/WvWFGatrK8UMuzqUJ9xyP3Cn7RL0waEo1V4vwsn9X3ES RcWm2MNfwzwdTRInxbuXXYeJyZVylf3mgAnxjIWC9A61weT46UJScaBKZb6CTJ95fdXc4W 0Xobp97QP/Ys679zXnI7BDU1rkSIxdo/jpLdEXH3UTkH+Lj9VlrNblL8TzAy1w== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791386731; b=vapIYe8fyHGJ2LOYsCn5yBqVJtPiJtM4Ui1kMrCd6vLUMcK0FzJ3z2gY/AIUHtJNbBY+a7 wfv1IrY5aHNwK2Rw/pZKH/7y+gmIEoTa9v7SK0KLOp4KSC14+FkdQy7OqF2l5+fsShZvNO w5kJM4l4TPyF6NmP2FjRv43tJYBa29tR2ilcAeI9ZfT7tiLomrOlePrwb8k0yRQCKCl2uh m/msYHAKXAuonps3lTvd3qq29LY2YW59hWZqbkg6tiFZR+MvXqorY5viyduDLbJugBUume 7aSaCmcKBc1fxdDkUGhlHAw6eQDetL2r61yVs7lXDqCCRJn/D+6HHg320SaEjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791386731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjiZY7t16375uszfCoNb2V1RFbqpvI2Ni3X40g3LQCM=; b=QRIrtTLfJSgTWX0FHsqmnlt9hhqhr4OC5ECcVh6wBQZxlLMAyixtimIrPUllLszX69jHI2 IayIoS8eFIgCCq/bxgl9bGJIFRaxJwK6T2XaI1nMdTvLiFoZ6VwOdFp9MV7UTUNZbo8h0s X/7f0LsqjEz9zwdYEvETUfXCSsfrrgfmrncZufHGo08g71yFh0hpgujS2O8DsaZs/aUTsa 3SWLWSmv5uAw7oyRWYuN2nnZJx34zPU0RIymazWoWSvb3Tual5VGt1GMEvMY1CfTOdJcHF Wta+wwYNXW/OBhOnhXknvr6u6GnxfEc5arrTkK6iv3ocpztfy8PkFPRo0q+2eA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j0H4q44Jnzygv for ; Wed, 07 Oct 2026 15:25:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 240d2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 07 Oct 2026 15:25:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Krzysztof Galazka From: Fernando Apeste=?utf-8?Q?gu=C3=ADa?= Subject: git: e7b019fbf1a0 - main - whereis: Fix list size calculation. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fernape X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e7b019fbf1a0f02386a8d02eac4a691f112cc242 Auto-Submitted: auto-generated Date: Wed, 07 Oct 2026 15:25:31 +0000 Message-Id: <6ac6646b.240d2.682c100f@gitrepo.freebsd.org> The branch main has been updated by fernape: URL: https://cgit.FreeBSD.org/src/commit/?id=e7b019fbf1a0f02386a8d02eac4a691f112cc242 commit e7b019fbf1a0f02386a8d02eac4a691f112cc242 Author: Krzysztof Galazka AuthorDate: 2026-10-07 15:24:05 +0000 Commit: Fernando ApesteguĂ­a CommitDate: 2026-10-07 15:25:05 +0000 whereis: Fix list size calculation. Use nitems() to calculate the number of elements in sourcepaths. Reviewed by: fernape@, ngie@ Approved by: ngie@ Fixes: 3963483523a4 Sponsored by: Intel Corporation Assisted-by: Github Copilot (GPT-5.6 Terra) Differential Revision: https://reviews.freebsd.org/D60368 --- usr.bin/whereis/whereis.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c index 5f8aeb1cdbc1..d8dabd056039 100644 --- a/usr.bin/whereis/whereis.c +++ b/usr.bin/whereis/whereis.c @@ -33,6 +33,7 @@ */ #include +#include #include #include @@ -249,7 +250,7 @@ colonify(ccharp *cpp) static void defaults(void) { - size_t s; + size_t i, s; char *b, buf[BUFSIZ], *cp; const char *path_ports; int nele; @@ -307,9 +308,11 @@ defaults(void) /* -s defaults to precompiled list, plus subdirs of * $PORTSDIR. If not set, it defaults to /usr/ports */ if (!sourcedirs) { - size_t sp_len = strlen(*sourcepaths); - sourcedirs = malloc(sp_len * sizeof (char *)); - for (size_t i = 0; i < sp_len; i++) + s = nitems(sourcepaths); + sourcedirs = malloc(s * sizeof(char *)); + if (sourcedirs == NULL) + abort(); + for (i = 0; i < s; i++) sourcedirs[i] = sourcepaths[i]; path_ports = getenv("PORTSDIR"); @@ -329,6 +332,15 @@ defaults(void) return; if ((dir = opendir(path_ports)) == NULL) err(EX_OSERR, "opendir(%s)", path_ports); + + /* + * Move the index one element back so if we end up adding some + * port directories, we place them back to back to the + * sourcepaths and the NULL element shows only at the end (used + * later on as end-o-array marker) + */ + --i; + while ((dirp = readdir(dir)) != NULL) { /* * Not everything below path_ports is of @@ -360,11 +372,11 @@ defaults(void) continue; } sourcedirs = realloc(sourcedirs, - (nele + 2) * sizeof(char *)); + (i + 2) * sizeof(char *)); if (sourcedirs == NULL) abort(); - sourcedirs[nele++] = b; - sourcedirs[nele] = NULL; + sourcedirs[i++] = b; + sourcedirs[i] = NULL; } closedir(dir); }