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?

Note: The description does not explicitly say that s needs to be
an array in all cases (just like in the free() case, where a null
pointer is allowed though its description first says "The free()
function shall cause the space pointed to by ptr to be deallocated"
unconditionally).

If this is valid, this would make the glibc incorrect as it uses
__nonnull in the strnlen declaration. Otherwise, a null pointer
should explicitly be disallowed.

-- 
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

  • Is strnlen(0,0) val... Vincent Lefevre via austin-group-l at The Open Group
    • Re: Is strnlen... Jonathan Wakely via austin-group-l at The Open Group
      • Re: Is str... Vincent Lefevre via austin-group-l at The Open Group
        • Re: Is... Geoff Clare via austin-group-l at The Open Group
          • Re... Vincent Lefevre via austin-group-l at The Open Group
            • ... Geoff Clare via austin-group-l at The Open Group
              • ... Vincent Lefevre via austin-group-l at The Open Group
                • ... Geoff Clare via austin-group-l at The Open Group
                • ... Vincent Lefevre via austin-group-l at The Open Group
                • ... Alejandro Colomar via austin-group-l at The Open Group
                • ... Geoff Clare via austin-group-l at The Open Group

Reply via email to