public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH 2/4] string.3 fixes
Date: Mon, 13 Nov 2023 01:53:04 +0100	[thread overview]
Message-ID: <ZVFzcACjZYkjDOAZ@debian> (raw)
In-Reply-To: <20231112235218.80195-3-eggert@cs.ucla.edu>

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

Hi Paul,

On Sun, Nov 12, 2023 at 03:52:06PM -0800, Paul Eggert wrote:
> strncpy’s src need not be a string; it can be an array that
> is not null-terminated.  Reword so as to not imply that
> the result always has some null padding.  Use “byte” rather
> than “character” to avoid issues with “character”, as
> not every byte is a valid character in (for example) UTF-8 locales.
> Replace “‐” (U+2020 HYPHEN) with “-” (U+002D HYPHEN-MINUS).

I fixed the hyphen typo in a separate commit:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=6be4cc77bb91dd25c48952b647ff49d52c16ab7a>

> ---
>  man3/string.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/string.3 b/man3/string.3
> index bd8b342a6..4037fce47 100644
> --- a/man3/string.3
> +++ b/man3/string.3
> @@ -185,8 +185,8 @@ bytes to
>  const char " src "[restrict ." n ],
>  .BI "       size_t " n );
>  .fi
> -Fill a fixed‐width buffer with characters from a string
> -and pad with null bytes.
> +Fill a fixed-size buffer with non-null bytes from a source array,

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'?  It is certainly part of the array,
and is non-null.  While saying that it only reads strings is incomplete,
I'm not sure this alternative is complete either.

> +padding with null bytes as needed.

I've split the patch into several pieces:
-  Clarify that dst isn't padded if there's no room.
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=1873da38de4be3d36bb67d011b907f6f774eef82>

-  Talk about bytes, not characters:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=f51cbcca1c0e12e94590bd9723e3e446ac50c33a>

Thanks!
Alex

>  .SH DESCRIPTION
>  The string functions perform operations on null-terminated
>  strings.
> -- 
> 2.41.0
> 
> 

-- 
<https://www.alejandro-colomar.es/>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-11-13  0:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-12 23:52 [PATCH 0/4] improvements for strncpy.3 etc Paul Eggert
2023-11-12 23:52 ` [PATCH 1/4] * Remove man3/stpecpyx.3; no longer present Paul Eggert
2023-11-13  0:18   ` Alejandro Colomar
2023-11-12 23:52 ` [PATCH 2/4] string.3 fixes Paul Eggert
2023-11-13  0:53   ` Alejandro Colomar [this message]
2023-11-13 22:27     ` Paul Eggert
2023-11-13 23:25       ` Alejandro Colomar
2023-11-12 23:52 ` [PATCH 3/4] strncat.3 fixes Paul Eggert
2023-11-13  1:15   ` Alejandro Colomar
2023-11-13 16:23     ` Alejandro Colomar
2023-11-21 16:03     ` Alejandro Colomar
2023-11-12 23:52 ` [PATCH 4/4] stpncpy(3) fixes Paul Eggert
2023-11-13  1:29   ` Alejandro Colomar
2023-11-21 18:33     ` Alejandro Colomar
2023-11-21 21:18       ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZVFzcACjZYkjDOAZ@debian \
    --to=alx@kernel.org \
    --cc=eggert@cs.ucla.edu \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox