Oops
I forgot to cleanup and did so with an incremental

diff --git a/lib/string.c b/lib/string.c
index 445acd7..6e85462 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -16,7 +16,6 @@
 
 #include <config.h>
 #include <ctype.h>
-#include <stdio.h>
 #include <string.h>
 
 #include "util.h"
@@ -44,9 +43,7 @@ char *strcasestr_s(const char *str, const char *substr)
     int si = 0;  /* string index. */
     int wsi = 0; /* working string index. */
     int ssi = 0; /* substring index. */
-    const char *save_str;
     while (str[si]) {
-        save_str = &str[si];
         while (substr[ssi]) {
             if (toupper(str[wsi]) == toupper(substr[ssi])) {
                 ssi++;
@@ -60,7 +57,7 @@ char *strcasestr_s(const char *str, const char *substr)
         }
         /* We matched the substring. */
         if (!substr[ssi]) {
-            return CONST_CAST(char *, save_str);
+            return CONST_CAST(char *, &str[si]);
         }
     }
     return NULL;


-----Original Message-----
From: <[email protected]> on behalf of Darrell Ball 
<[email protected]>
Date: Thursday, August 3, 2017 at 1:49 PM
To: "[email protected]" <[email protected]>, "[email protected]" 
<[email protected]>
Subject: [ovs-dev] [patch_v7 1/6] string: Implement strcasestr if it is missing.

    strcasestr is not defined for Windows, so implement a version
    that could be used on Windows. This is needed for an upcoming
    patch.
    
    Signed-off-by: Darrell Ball <[email protected]>
    ---
     lib/string.c    | 41 ++++++++++++++++++++++++++++++++++++++++-
     lib/string.h.in |  1 +
     2 files changed, 41 insertions(+), 1 deletion(-)
    
    diff --git a/lib/string.c b/lib/string.c
    index 082359d..445acd7 100644
    --- a/lib/string.c
    +++ b/lib/string.c
    @@ -15,9 +15,14 @@
      */
     
     #include <config.h>
    -
    +#include <ctype.h>
    +#include <stdio.h>
     #include <string.h>
     
    +#include "util.h"
    +
    +char *strcasestr_s(const char *str, const char *substr);
    +
     #ifndef HAVE_STRNLEN
     size_t
     strnlen(const char *s, size_t maxlen)
    @@ -26,3 +31,37 @@ strnlen(const char *s, size_t maxlen)
         return end ? end - s : maxlen;
     }
     #endif
    +
    +char *strcasestr_s(const char *str, const char *substr)
    +{
    +    if (!str || !substr) {
    +        return NULL;
    +    }
    +    if (strlen(substr) > strlen(str)) {
    +        return NULL;
    +    }
    +
    +    int si = 0;  /* string index. */
    +    int wsi = 0; /* working string index. */
    +    int ssi = 0; /* substring index. */
    +    const char *save_str;
    +    while (str[si]) {
    +        save_str = &str[si];
    +        while (substr[ssi]) {
    +            if (toupper(str[wsi]) == toupper(substr[ssi])) {
    +                ssi++;
    +                wsi++;
    +            } else {
    +                ssi = 0;
    +                si++;
    +                wsi = si;
    +            }
    +            break;
    +        }
    +        /* We matched the substring. */
    +        if (!substr[ssi]) {
    +            return CONST_CAST(char *, save_str);
    +        }
    +    }
    +    return NULL;
    +}
    diff --git a/lib/string.h.in b/lib/string.h.in
    index bbdaeb4..5a86ea3 100644
    --- a/lib/string.h.in
    +++ b/lib/string.h.in
    @@ -36,6 +36,7 @@
     #define strcasecmp _stricmp
     #define strncasecmp _strnicmp
     #define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
    +#define strcasestr(str, substr) strcasestr_s(str, substr)
     #endif
     
     #ifndef HAVE_STRNLEN
    -- 
    1.9.1
    
    _______________________________________________
    dev mailing list
    [email protected]
    
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_mailman_listinfo_ovs-2Ddev&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=BVhFA09CGX7JQ5Ih-uZnsw&m=UuUhz59pgdltjTtw-zjb3rqploJd7bCKsFL5WV94rwM&s=PDBnCOWsyFBld7wKDY5PZODfZvU2MdmIC1hgSCS8r_U&e=
 
    

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to