Re: [PATCH 2/4] string.3 fixes

Paul Eggert
2023-11-13T22:27:56Z

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

On 11/12/23 16:53, Alejandro Colomar wrote:
> I'm not convinced by the array wording, as it could be understood as
> doing this:
>
> char d[3], s[3] = {'a', '\0', 'b'};
>
> strncpy(d, s, 3); // "a\0b"? Or maybe "ab\0"?
>
> Did it copy the non-null byte 'b'?

OK, let's fix that confusion by saying it copies "leading non-null
bytes", not merely "non-null bytes". Please see attached.

[-- Attachment #2: 0001-string.3-fixes.patch --]
[-- Type: text/x-patch, Size: 1021 bytes --]

From ac104738b8b13159271c40a86341f871fa260e33 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 13 Nov 2023 14:26:42 -0800
Subject: [PATCH] string.3 fixes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Say "size" not "width" for byte counts; "width" is for the number
of bits in a word. Say "leading" to make it clear we don’t care
about what the source contains, after its first null byte.
---
man3/string.3 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/string.3 b/man3/string.3
index 4c374a7df..08b050b17 100644
--- a/man3/string.3
+++ b/man3/string.3
@@ -185,7 +185,7 @@ bytes to
const char " src "[restrict ." n ],
.BI " size_t " n );
.fi
-Fill a fixed-width buffer with non-null bytes from a source string,
+Fill a fixed-size buffer with leading non-null bytes from a source array,
padding with null bytes as needed.
.SH DESCRIPTION
The string functions perform operations on null-terminated
--
2.41.0