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 @@ ...@@ -23,13 +23,16 @@
#endif #endif
#include <string.h> #include <string.h>
#include <assert.h>
char * strnstr (const char *haystack, const char *needle, size_t len) char * strnstr (const char *haystack, const char *needle, size_t len)
{ {
if(!needle || !*needle) assert(needle != NULL);
return (char*)haystack;
const size_t i = strlen(needle); const size_t i = strlen(needle);
if (i == 0) /* corner case (if haystack is NULL, memcmp not allowed) */
return (char *)haystack;
if( len < i ) if( len < i )
return NULL; 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