This paper is intended to propose similar wording to that agreed for POSIX to be applied to C1x to keep both standards in alignment. Without this change, POSIX would keep their new wording, but it would be marked as a C extension.
In contrast, consider the wording for fprintf when dealing with the %.*s specifier, in POSIX from line 29938:
If the precision is not specified or is greater than the size of the array, the application shall ensure that the array contains a null byte.Many implementations of the *printf family use memchr to implement this statement; for example, http://git.sv.gnu.org/cgit/gnulib.git/tree/lib/vasnprintf.c?id=d4ca645#n197.
However, if memchr does not have any strict requirement on evaluation order, then this invokes undefined behavior. Likewise, application writers have noticed that it is possible to write faster code for finding a NUL byte, if one is present within a bounded length, by using memchr rather than strnlen, since the former has fewer conditionals (bounds check and search for NUL) than the latter (bounds check, search for NUL, and search for c). But again, this usage is rendered unsafe unless memchr is specified to behave like strnlen and not dereference past the match.
The memchr( ) function shall locate the first occurrence of c (converted to an unsigned char) in the initial n bytes (each interpreted as unsigned char) of the object pointed to by s.In the RETURN VALUE section change
The memchr( ) function shall return a pointer to the located byte, or a null pointer if the byte does not occur in the object.to
The memchr( ) function shall return a pointer to the located byte, or a null pointer if the byte is not found.Add to DESCRIPTION
Implementations shall behave as if they read the memory byte by byte from the beginning of the bytes pointed to by s and stop at the first occurrence of c (if it is found in the initial n bytes).
Implementations shall behave as if they read the memory byte by byte from the beginning of the bytes pointed to by s and stop at the first occurrence of c (if it is found in the initial n bytes).