From nobody Thu Feb 16 00:41:31 2023 X-Original-To: dev-commits-src-all@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 4PHGNC5XzHz3rYw4; Thu, 16 Feb 2023 00:41: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHGNC4tW2z43jv; Thu, 16 Feb 2023 00:41:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676508091; 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=125znxd02kJM4vpCBoWESOV0NX1uE7Wx+MI3kA6h0+c=; b=x2SHJgLZKC/5XsDpGPwbi7SKCimyaQhC4KxEOPm2MYOPIlJs4om0yEkBMOXNO+WXnEJCpF h/Dxvy6OMg9bn4bnUBYqk3fnslZ+nP1fLfapLA/amObNQ1EBUxr/rRHp1enhl0wkXQxZ2T etfkQOUVCxYra/kIwQH0iJnTVhBGv0KWrx3b4+Go5WiAT87j4r8h5GzmKNWrtUIedieVVN 5UkwYaCfzohpri7AGAU2sZRJQAhO/Zi4LYEgjxrKRe4RkMhoYKBAWSNjtb2dZoXkIhTwtF zG8pPBHsI29ShndFfVhdfIWiVhIMq9IlkN+uDTOzdOCeJNOkcbj+EIl2GgpMOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676508091; 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=125znxd02kJM4vpCBoWESOV0NX1uE7Wx+MI3kA6h0+c=; b=BtFGcPm7/ORX/VasVYZO0kOcGBMDIM0v1wLcKjHvHKlIuJ0K7LayYuMf+lPBx1k6YZOzlE nyg5t3g7UufI5r//njMAuYOAzJHyJ32Zb7jzcjDhbCHTnppg2qz6/Cv3OTpBbr2iXyb0VD fSEKx/7FuWXeHYMBopvOJG0WsPfCVZjpminNVyCHo4Nbug2jFKQ9tlqBHIsckWPfdKGTg8 pzLCLH2GaRZnZSSeQallFeom+aRe2vHn8uVHGiYgVzKrRWuUvYqeZZ1wS/VUfoH0ghmwv7 APcvEnhjQwgdlJCI5TQU+6UJSgLYo8G/megHO2RGUIy9bipFcp3gValHUDoPhg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676508091; a=rsa-sha256; cv=none; b=wKSagzo4ISsunXeAQTEryPvORRIpkzCGjCaD47cQDbFyKhV6GMm0LXdr7oaxvLC1q+kZwK UHVo37rXxAI7cQ1O8f2cAN4u7J2RqGlwg8G+0nzKomYYk+jvc8tAl4Ey6IpQaBtjXknu/2 sKQvO4ANROjSllXIuxaAQakOpxg6P2+tLxjV1YOIardTsCmcluNHLkz5eUrLoWOXqWsfg5 woQnnOL/HfJjGLAUE/l70ddjMOVgkXUsPYRX052EqllTSFwweRPq9YRIXwFBw22umqtq1p uzQK6xkf+DD8LT/sIjd6HPefitsZP2QQ+lcC8NIGjjACwK9Wd4wHzGLqi3Y2tg== 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 4PHGNC3spqzkfW; Thu, 16 Feb 2023 00:41:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31G0fV5s098196; Thu, 16 Feb 2023 00:41:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31G0fVIa098195; Thu, 16 Feb 2023 00:41:31 GMT (envelope-from git) Date: Thu, 16 Feb 2023 00:41:31 GMT Message-Id: <202302160041.31G0fVIa098195@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 5016d112ad8b - main - wc: Make the read buffer static. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 5016d112ad8b259047920f3a2f749c369982de37 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=5016d112ad8b259047920f3a2f749c369982de37 commit 5016d112ad8b259047920f3a2f749c369982de37 Author: Dag-Erling Smørgrav AuthorDate: 2023-02-16 00:40:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-02-16 00:40:45 +0000 wc: Make the read buffer static. The read buffer in cnt() is 64 kB, which is a bit excessive for a stack variable. MAXBSIZE has grown since this code was originally written, and it might grow again in the future. Since the program is single-threaded and cnt() does not recurse, we can safely make the buffer static. While there, constify p since it is only used to read. Sponsored by: Klara, Inc. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D38608 --- usr.bin/wc/wc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index 9c129917dd04..6ba827612e3d 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -214,9 +214,10 @@ show_cnt(const char *file, uintmax_t linect, uintmax_t wordct, static int cnt(const char *file) { - char buf[MAXBSIZE], *p; + static char buf[MAXBSIZE]; struct stat sb; mbstate_t mbs; + const char *p; uintmax_t linect, wordct, charct, llct, tmpll; ssize_t len; size_t clen; @@ -259,7 +260,7 @@ cnt(const char *file) * lines than to get words, since the word count requires locale * handling. */ - while ((len = read(fd, buf, sizeof(buf)))) { + while ((len = read(fd, buf, sizeof(buf))) != 0) { if (len < 0) { xo_warn("%s: read", file); (void)close(fd);