Thread (5 messages) 5 messages, 2 authors, 2024-07-22

Re: Ambiguity in memccpy() description, with patch

From: Alejandro Colomar <alx@kernel.org>
Date: 2024-07-15 21:29:41

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.)
Agree.  It is implied by the RETURN VALUE section, but the description
didn't say it (and the RETURN VALUE only implied it).
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)
I'd remove the parenthesis.  That conversion is of course, no?  For the
standard, it makes sense to be pedantic, but for a user, I doubt the
value of that statement.

Especially with this function.  My personal recommendation, after having
researched so much about strings these last years, is that this function
is useless (unless you're restricted to ISO C, and even then, it is,
because you can write better functions as wrappers to ISO C functions).

May I ask if you have any specific need for string handling?  I'm
developing a string library, libs, and I'm interested in feedback of
possible users (for now, the targeted user is shadow utils).
quoted hunk ↗ jump to hunk
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:
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()
Missing a space here before the ().
+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.
+(converted to an
+.BR "unsigned char" )
+is copied, or after
+.I n
+bytes are copied, whichever
+comes first.
Please break after the comma.
 .P
-If the memory areas overlap, the results are undefined.
+If copying takes place between objects that overlap,
+the behavior is undefined.
 .SH RETURN VALUE
 The
 .BR memccpy ()
Have a lovely night!
Alex

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

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help