Skip to content

Commit

Permalink
strnstr: needle cannot be NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Denis-Courmont committed Oct 26, 2015
1 parent a2ee2cd commit 32adc07
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compat/strnstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 32adc07

Please sign in to comment.