vlc | branch: master | Francois Cartegnie <[email protected]> | Wed Oct  7 
19:38:25 2015 +0200| [db41ce0a1692b5894ca93122932c6e3f7cb718b6] | committer: 
Francois Cartegnie

compat: fix strnstr

need to wake up sometimes :/

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

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

diff --git a/compat/strnstr.c b/compat/strnstr.c
index badf7d8..3e1f6d5 100644
--- a/compat/strnstr.c
+++ b/compat/strnstr.c
@@ -26,18 +26,22 @@
 
 char * strnstr (const char *haystack, const char *needle, size_t len)
 {
+    if(!needle || !*needle)
+        return (char*)haystack;
+
     const size_t i = strlen(needle);
-    if( i < len )
+    if( len < i )
       return NULL;
     
     size_t count = len - i;
 
-    while(count)
+    do
     {
       if( memcmp(haystack, needle, i) )
         return (char*) haystack;
-      count--;
       haystack++;
     }
+    while(count--);
+
     return NULL;
 }

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to