Hi Chan, > Date: 2026-10-29 22:59:27-0400 > From: 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 > --- > 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) > > --