https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111615
--- Comment #6 from Ben Gardner <gardner.ben at gmail dot com> --- (In reply to Andrew Pinski from comment #5) > extern void *memmem (const void *__haystack, size_t __haystacklen, > const void *__needle, size_t __needlelen) > __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) > __attribute__ ((__nonnull__ (1, 3))); > > > memmem is declared with nonnull for the 1st and 3rd argument. If those > arguments are null, the behavior is undefined and the values of those > arguments can be assumed as not null afterwards too. > > If you don't want that behavior you can use -fno-delete-null-pointer-checks . > > Otherwise the behavior you are seeing is correct behavior based on well > defined code. Thanks for the info. That makes sense. I didn't check the header file, so I didn't know that memmem() was declared with nonnull. Also, thanks for the tip about -fno-delete-null-pointer-checks.