On Tue, 10 Sept 2024 at 11:36, Vincent Lefevre via austin-group-l at The Open Group <austin-group-l@opengroup.org> wrote: > > About the strnlen() function > > size_t strnlen(const char *s, size_t maxlen); > > in the strnlen description from > > https://pubs.opengroup.org/onlinepubs/9799919799/functions/strnlen.html > > "The strnlen() function shall never examine more than maxlen bytes > of the array pointed to by s." > > So, when maxlen is 0, the strnlen() function shall not examine any > byte. Does this imply that in this case, s may be a null pointer?
The C standard says you cannot pass null pointers to functions in <string.h> even with a length of zero. I think it's reasonable to assume that the rules for all functions in <string.h> in the C standard also apply to POSIX extensions in <string.h>. Otherwise, code written for the POSIX strnlen might become undefined if/when strnlen gets adopted by the C standard and null pointers are no longer valid.