* [PATCH] man/man3/strncpy.3: Document lack of terminating null byte
@ 2026-10-30 2:59 Chan Lee
2026-10-30 13:34 ` Alejandro Colomar
0 siblings, 1 reply; 2+ messages in thread
From: Chan Lee @ 2026-10-30 2:59 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: linux-man, Chan Lee
The lack of a terminating null byte is already shown by the examples in
CAVEATS, but DESCRIPTION does not explain the condition under which it
happens. A reader who only reads DESCRIPTION may miss this behavior.
This patch makes this behavior easier to discover by stating explicitly
that no terminating null byte is written when the source has dsize or
more non-null bytes.
Signed-off-by: Chan Lee <chanlee031012@gmail.com>
---
man/man3/strncpy.3 | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/man/man3/strncpy.3 b/man/man3/strncpy.3
index 9c476acb4..89da260fe 100644
--- a/man/man3/strncpy.3
+++ b/man/man3/strncpy.3
@@ -26,6 +26,10 @@ into the array pointed to by
.IR dst .
If the source has too few non-null bytes to fill the destination,
it pads the destination with trailing null bytes.
+If the source has
+.I dsize
+or more non-null bytes,
+no terminating null byte is written to the destination.
If the destination buffer,
limited by its size,
isn't large enough to hold the copy,
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] man/man3/strncpy.3: Document lack of terminating null byte
2026-10-30 2:59 [PATCH] man/man3/strncpy.3: Document lack of terminating null byte Chan Lee
@ 2026-10-30 13:34 ` Alejandro Colomar
0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Colomar @ 2026-10-30 13:34 UTC (permalink / raw)
To: Chan Lee; +Cc: linux-man
[-- Attachment #1: Type: text/plain, Size: 2582 bytes --]
Hi Chan,
> Date: 2026-10-29 22:59:27-0400
> From: Chan Lee <chanlee031012@gmail.com>
>
> The lack of a terminating null byte is already shown by the examples in
> CAVEATS, but DESCRIPTION does not explain the condition under which it
> happens. A reader who only reads DESCRIPTION may miss this behavior.
>
> This patch makes this behavior easier to discover by stating explicitly
> that no terminating null byte is written when the source has dsize or
> more non-null bytes.
>
> Signed-off-by: Chan Lee <chanlee031012@gmail.com>
> ---
> man/man3/strncpy.3 | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/man/man3/strncpy.3 b/man/man3/strncpy.3
> index 9c476acb4..89da260fe 100644
> --- a/man/man3/strncpy.3
> +++ b/man/man3/strncpy.3
> @@ -26,6 +26,10 @@ into the array pointed to by
> .IR dst .
> If the source has too few non-null bytes to fill the destination,
> it pads the destination with trailing null bytes.
> +If the source has
> +.I dsize
> +or more non-null bytes,
> +no terminating null byte is written to the destination.
Actually, this function never writes a *terminating* null byte.
It writes padding null bytes in some cases, but those should not be used
for terminating a string.
The wording of the page is written so that users are discouraged from
using this as a function for handling strings at all.
NAME
strncpy - nonstring copy
...
DESCRIPTION
This function copies non‐null characters from the string
pointed to by src into the array pointed to by dst. If
the source has too few non‐null bytes to fill the destina‐
tion, it pads the destination with trailing null bytes.
...
CAVEATS
The name of this function is confusing. This function
produces a null‐padded character sequence, not a string
(see string_copying(7)). For example:
The lack of a terminating null byte is implicit in the fact that the
page never says it produces a string, and it says it copies non-null
bytes (plus optional padding). The CAVEATS even explicitly say it
doesn't produce a string.
I think the proposed patch would be negative, in that it would confuse
readers to believe this function is appropriate for producing strings
under some conditions, while it is never appropriate for that.
Have a lovely day!
Alex
> If the destination buffer,
> limited by its size,
> isn't large enough to hold the copy,
> --
> 2.50.1 (Apple Git-155)
>
>
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-30 13:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 2:59 [PATCH] man/man3/strncpy.3: Document lack of terminating null byte Chan Lee
2026-10-30 13:34 ` Alejandro Colomar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox