git: 557ba0c2a513 - main - yes: Avoid static initialization

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Mon, 17 Aug 2026 16:04:48 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=557ba0c2a5138ce026c0ea9cb02f374f97378b7c

commit 557ba0c2a5138ce026c0ea9cb02f374f97378b7c
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-08-17 16:04:35 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-08-17 16:04:35 +0000

    yes: Avoid static initialization
    
    Our buffer is half a megabyte, but we are only initializing the first
    two bytes.  Switching from static to dynamic initialization moves it
    from .data to .bss, greatly reducing the size of the binary.
    
    Fixes:          cf74b63d61b4 ("yes: Completely overengineer")
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D58890
---
 usr.bin/yes/yes.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/usr.bin/yes/yes.c b/usr.bin/yes/yes.c
index 86022c82f453..66bb01d4de47 100644
--- a/usr.bin/yes/yes.c
+++ b/usr.bin/yes/yes.c
@@ -55,9 +55,9 @@
 int
 main(int argc, char **argv)
 {
-	static char buf[MAXBUF] = EXP;
-	char *end = buf + sizeof(buf), *exp, *pos = buf + EXPLEN;
-	size_t buflen, explen = EXPLEN;
+	static char buf[MAXBUF];
+	char *end = buf + sizeof(buf), *exp, *pos;
+	size_t buflen, explen;
 	ssize_t wlen = 0;
 
 	if (caph_limit_stdio() < 0 || caph_enter() < 0)
@@ -83,6 +83,10 @@ main(int argc, char **argv)
 			pos = end - 2;
 		*pos++ = '\n';
 		explen = pos - buf;
+	} else {
+		memcpy(buf, EXP, EXPLEN);
+		pos = buf + EXPLEN;
+		explen = EXPLEN;
 	}
 
 	/*