[vlc-commits] strnstr: needle cannot be NULL

Rémi Denis-Courmont git at videolan.org
Mon Oct 26 18:36:45 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Oct 12 23:31:53 2015 +0300| [32adc07bd6cbbafdf8a0cabd89025d1944b9367a] | committer: Rémi Denis-Courmont

strnstr: needle cannot be NULL

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=32adc07bd6cbbafdf8a0cabd89025d1944b9367a
---

 compat/strnstr.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/compat/strnstr.c b/compat/strnstr.c
index 3e1f6d5..abdc3ea 100644
--- a/compat/strnstr.c
+++ b/compat/strnstr.c
@@ -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;
     



More information about the vlc-commits mailing list