Commit 32adc07b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

strnstr: needle cannot be NULL

parent a2ee2cdd
......@@ -23,13 +23,16 @@
#endif
#include <string.h>
#include <assert.h>
char * strnstr (const char *haystack, const char *needle, size_t len)
{
if(!needle || !*needle)
return (char*)haystack;
assert(needle != NULL);
const size_t i = strlen(needle);
if (i == 0) /* corner case (if haystack is NULL, memcmp not allowed) */
return (char *)haystack;
if( len < i )
return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment