https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104854
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> --- I forgot this strndup pitfall that POSIX cautions about in its APPLICATION USAGE and that the warning helps avoid: 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. Most implementations, including Glibc, only allocate strnlen (s, size) (i.e., less than size if s is shorter). Since the only motivating test case here is strndup and since it turned out that the patch submitted for this report was based on a misunderstanding of the warning (https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591926.html) and didn't do anything for strndup I'm going to resolve this as invalid. If you want to raise problems about the warning for strnlen or strncmp please open separate bugs and attach test cases, preferably from real code. None of those provided by Steve Grubb appears to have anything to do with strnlen or strncmp.