[PATCH v2] manual: Update memchr description [BZ #19406]
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Tue Jun 16 14:43:05 GMT 2026
Hi Paul,
> This behavior guarantee applies to memchr but not to
> memcmp/wmemchr/etc., and that should probably be documented. Also, "is
> read" clashes with "stops". Something like the following instead, perhaps?
>
Thanks, that looks reasonable. v2 below.
Cheers,
Wilco
v2: Update description after review
Update memchr description to indicate it cannot overread and the
size input may be larger than the object passed. This is required
since C11.
Suggested-by: Paul Eggert <eggert@cs.ucla.edu>
---
diff --git a/manual/string.texi b/manual/string.texi
index 24004f1f5cc60b70bafde0794351734a4eb1ce2b..b7a9ba0d46a01ea1a945b5c77cdac8825d626efb 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -1803,6 +1803,12 @@ to an @code{unsigned char}) in the initial @var{size} bytes of the
object beginning at @var{block}. The return value is a pointer to the
located byte, or a null pointer if no match was found.
+This function behaves as if it reads the bytes sequentially and stops at
+the first match, which means that if the object contains a match the
+behavior is defined even when the object size is less than @var{size}.
+This behavior guarantee is unusual, and is not shared by related
+functions like @code{memcmp} and @code{wmemchr}.
+
In ISO C23 and later, this function is qualifier-generic:
that is, it is also implemented as a function-like macro,
and when the macro is used and @var{block} has a type
More information about the Libc-alpha
mailing list