The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5016d112ad8b259047920f3a2f749c369982de37

commit 5016d112ad8b259047920f3a2f749c369982de37
Author:     Dag-Erling Smørgrav <[email protected]>
AuthorDate: 2023-02-16 00:40:30 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
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);

Reply via email to