git: ed87197672b4 - stable/13 - uname: -v: strip final whitespace compatibly with uname(3)

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Sat, 05 Mar 2022 19:56:56 UTC
The branch stable/13 has been updated by mjg:

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

commit ed87197672b44f7f76b38e6450df2b4071c88a67
Author:     наб <nabijaczleweli@nabijaczleweli.xyz>
AuthorDate: 2022-02-18 13:34:40 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-03-05 19:56:11 +0000

    uname: -v: strip final whitespace compatibly with uname(3)
    
    This restores POSIX.1 conformance
    
    PR: 260938
    (cherry picked from commit 7e05fa3b449007adaa6e588ebb3b8d76f30b355c)
---
 usr.bin/uname/uname.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/usr.bin/uname/uname.c b/usr.bin/uname/uname.c
index e97b9c3cb744..109505e4b9da 100644
--- a/usr.bin/uname/uname.c
+++ b/usr.bin/uname/uname.c
@@ -256,8 +256,12 @@ NATIVE_SYSCTL2_GET(version, CTL_KERN, KERN_VERSION) {
 	p = NATIVE_BUFFER;
 	n = NATIVE_LENGTH;
 	for (; n--; ++p)
-		if (*p == '\n' || *p == '\t')
-			*p = ' ';
+		if (*p == '\n' || *p == '\t') {
+			if (n > 1)
+				*p = ' ';
+			else
+				*p = '\0';
+		}
 } NATIVE_SET;
 
 NATIVE_SYSCTL2_GET(platform, CTL_HW, HW_MACHINE) {