Warner Losh <[email protected]> writes:
> As for memchr,
> https://pubs.opengroup.org/onlinepubs/009696799/functions/memchr.html
> has no such permission to examine 'the entire buffer at once' nor any
> restirction
> as to the length extending beyond the address space. I'm skeptical of your
> reading
> that it allows one to examine all of [b, b + len), so please explain where
> the standard
> supports reading past the first occurance.
C11 says:
(7.24.4.1 §2) The memcmp function compares the first n characters of
the object pointed to by s1 to the first n characters of the object
pointed to by s2.
and
(7.24.5.1 §2) The memchr function locates the first occurrence of c
(converted to an unsigned char) in the initial n characters (each
interpreted as unsigned char) of the object pointed to by s. The
implementation shall behave as if it reads the characters
sequentially and stops as soon as a matching character is found.
The second sentence in the description of memchr() means a bogus length
is allowed as long as we get a match before we read past the end of the
object. There is no such provision for memcmp(), so calling memcmp()
with a bogus length invokes UB.
DES
--
Dag-Erling Smørgrav - [email protected]