From nobody Fri Nov 01 15:53:17 2024 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 4Xg54F5XjYz5c0xc; Fri, 01 Nov 2024 15:53:17 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xg54F4q0Zz4tbJ; Fri, 1 Nov 2024 15:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730476397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3THY3S51sgMoCfgLSuBFkLtummp/yPis+KCEdQkZQFg=; b=onT35JYLJ1NZJSvfXw6vxl1Xt/MNTShCxiCxoOuDN4/kqOEDz+vXJ9Zr41v70mVHjppB8O RQr5NUhppgRAO06UQt0eKOq+V/qHezVC9pUSzqiBtK0V1eAuSSYNU8ERAXHp93EUWqSFc7 hk1PB9IBHMO6XI2Xm4jGbtiL75+U1eBYBHc6psDURSaI2o1UgXX2rtIf8RulWaDxOOcr1L vw2ekhPLHOX+0fFncjXOF1YQClsf8muNS8VWtRE9k/itF1/o8rVEOMs2/slm2lxQGrbfuR S1hbL7dGBWJveC/Uoinu5Q5tOsCR9FAR8jC/y58oUsDmKV8EamTWkIKUKLIo8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730476397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3THY3S51sgMoCfgLSuBFkLtummp/yPis+KCEdQkZQFg=; b=bmibcFGR/LFL3DTjVGOJI9KTqIkTCEgksIa/0UjGwuqWtm5Sk44+wb1uANc6LC5o1B9euf HOO3kVLT7+/HA5LAbpiNeaofBbp6qwgHgR5TLvfw01l6KD1RF/3JM1PZ0FXdwsbkR9Lcyf AxLNM3I4C+gJ2tT+leb7FQ+C3Y+NY5yTU/o+4LTplwa6dF33wt0WInq08KfLZvgEa7sgC5 q1COqwMVdqr1mnIgViWeurXr8jeDQ8Vk8rDubmXcd8VEDuI185srP0444Od7yj2RTOYhBF wVC0A+UztwIO3euqW9EA1achI/Jcv1ouEAschFKBmbg7XZSuGitb9ZMH0uRooA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730476397; a=rsa-sha256; cv=none; b=e9AIfa8zcxSrIfxz+7Tw5OvhhhYBRLQcOKN3WKaRQTslkxnjVc9wFOTtU5O1LuvPAPdKYe RXbvwb7OtLLuThp6M9afOGVw2paBwcBOV6Ay1ZGhFAqN77sGtM3EPl9FAsvLr0Abmt8qVr G/S7xijYTkZ4/u1+mylrBWOeTEqaCU5CINbZQR1S5/AxyNVz8HfmYtD3xNkdTWNRJb/TVU KDnUo3JhpIbZxyo6t9mYcXbWKOe+PQq5ONP+Y9oEugM5y/6xQwaj9rz8JrbEmydgCky5sc V3w5wQTHYelyqSDc4RcxeKJpSBAiM63khPJHpBGmFx08XXvcwbHXnodaFXs/4A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xg54F45yqzRQZ; Fri, 1 Nov 2024 15:53:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A1FrHnh047160; Fri, 1 Nov 2024 15:53:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A1FrH3e047157; Fri, 1 Nov 2024 15:53:17 GMT (envelope-from git) Date: Fri, 1 Nov 2024 15:53:17 GMT Message-Id: <202411011553.4A1FrH3e047157@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 79679a18eacb - main - fts: Simplify fts_alloc() and use calloc(). 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 79679a18eacbd0f34d24d749ee379e3089045c00 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=79679a18eacbd0f34d24d749ee379e3089045c00 commit 79679a18eacbd0f34d24d749ee379e3089045c00 Author: Dag-Erling Smørgrav AuthorDate: 2024-11-01 15:51:56 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-11-01 15:53:11 +0000 fts: Simplify fts_alloc() and use calloc(). Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D47382 --- lib/libc/gen/fts.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 976edacc361e..770a7b2cc322 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1026,44 +1027,32 @@ fts_alloc(FTS *sp, char *name, size_t namelen) FTSENT *p; size_t len; - struct ftsent_withstat { - FTSENT ent; - struct stat statbuf; - }; - /* * The file name is a variable length array and no stat structure is * necessary if the user has set the nostat bit. Allocate the FTSENT * structure, the file name and the stat structure in one chunk, but * be careful that the stat structure is reasonably aligned. */ - if (ISSET(FTS_NOSTAT)) - len = sizeof(FTSENT) + namelen + 1; - else - len = sizeof(struct ftsent_withstat) + namelen + 1; - - if ((p = malloc(len)) == NULL) - return (NULL); - - if (ISSET(FTS_NOSTAT)) { - p->fts_name = (char *)(p + 1); - p->fts_statp = NULL; + len = sizeof(FTSENT) + namelen + 1; + if (!ISSET(FTS_NOSTAT)) { + len = roundup(len, alignof(struct stat)); + p = calloc(1, len + sizeof(struct stat)); } else { - p->fts_name = (char *)((struct ftsent_withstat *)p + 1); - p->fts_statp = &((struct ftsent_withstat *)p)->statbuf; + p = calloc(1, len); } + if (p == NULL) + return (NULL); - /* Copy the name and guarantee NUL termination. */ - memcpy(p->fts_name, name, namelen); - p->fts_name[namelen] = '\0'; - p->fts_namelen = namelen; + p->fts_symfd = -1; p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; + p->fts_name = (char *)(p + 1); + p->fts_namelen = namelen; p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; + if (!ISSET(FTS_NOSTAT)) + p->fts_statp = (struct stat *)((char *)p + len); p->fts_fts = sp; + memcpy(p->fts_name, name, namelen); + return (p); }