Re: Ambiguity in memccpy() description, with patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Keith,

On Mon, Jul 15, 2024 at 02:14:23PM GMT, Keith Thompson wrote:
> The current description in the memccpy.3 man page:
> 
>        The memccpy() function copies no more than n bytes from memory
> area src to memory area dest, stopping when the character c is found.
> 
>        If the memory areas overlap, the results are undefined.
> 
> doesn't clearly say whether the final character c is copied or not. (It is.)
> 
> This patch copies the description from POSIX
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/memccpy.html
> with the parameter names and added paragraph break retained from the
> current version. The updated description is:
> 
>        The memccpy() function copies bytes from memory area src into
> dest, stopping after the first occurrence of byte c (converted to an
> unsigned char) is copied, or after n bytes are copied, whichever comes
> first.
> 
>        If copying takes place between objects that overlap, the
> behavior is undefined.
> 
> I have not (yet) checked whether there are similar ambiguities in
> other man pages.
> 
> Patch follows:

I suggest some smaller change; see below.

> 
> diff --git man/man3/memccpy.3 man/man3/memccpy.3
> index 0ba805176..057890f7e 100644
> --- man/man3/memccpy.3
> +++ man/man3/memccpy.3
> @@ -23,20 +23,22 @@ Standard C library
>  .fi
>  .SH DESCRIPTION
>  The
> -.BR memccpy ()
> -function copies no more than
> -.I n
> -bytes from
> -memory area
> +.BR memccpy()
> +function copies bytes from memory area
>  .I src
> -to memory area
> +into
>  .IR dest ,
> -stopping when the
> -character
> +stopping after the first occurrence of byte
>  .I c
> -is found.

How about the following diff instead?:

diff --git i/man/man3/memccpy.3 w/man/man3/memccpy.3
index 0ba805176..e4701809a 100644
--- i/man/man3/memccpy.3
+++ w/man/man3/memccpy.3
@@ -34,7 +34,9 @@ .SH DESCRIPTION
 stopping when the
 character
 .I c
-is found.
+is found
+.RI ( c
+is copied).
 .P
 If the memory areas overlap, the results are undefined.
 .SH RETURN VALUE

That should be explicit enough, and keeps the changes minimal.

> +(converted to an
> +.BR "unsigned char" )
> +is copied, or after
> +.I n
> +bytes are copied, whichever
> +comes first.
>  .P
> -If the memory areas overlap, the results are undefined.
> +If copying takes place between objects that overlap,
> +the behavior is undefined.

I'd keep this out of this patch, since it's unrelated to c being copied
or not.

>  .SH RETURN VALUE
>  The
>  .BR memccpy ()

Have a lovely night!
Alex

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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux