https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96916
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> --- For strndup POSIX mentions the following application usage: Implementations are free to malloc() a buffer containing either (size + 1) bytes or (strnlen(s, size) + 1) bytes. Applications should not assume that strndup() will allocate ( size + 1) bytes when strlen(s) is smaller than size.