Piotr Caban : msvcrt: Update search position when no token was found in strtok.

Alexandre Julliard julliard at winehq.org
Tue May 25 16:08:16 CDT 2021


Module: wine
Branch: master
Commit: bf7244442de0dfdc5a13f6c6a1624fbf5b762ebb
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bf7244442de0dfdc5a13f6c6a1624fbf5b762ebb

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue May 25 18:00:15 2021 +0200

msvcrt: Update search position when no token was found in strtok.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/string.c       | 6 +++++-
 dlls/msvcrt/tests/string.c | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c
index d335fce4992..27e3284326a 100644
--- a/dlls/msvcrt/string.c
+++ b/dlls/msvcrt/string.c
@@ -287,7 +287,11 @@ char * CDECL strtok( char *str, const char *delim )
         if (!(str = data->strtok_next)) return NULL;
 
     while (*str && strchr( delim, *str )) str++;
-    if (!*str) return NULL;
+    if (!*str)
+    {
+        data->strtok_next = str;
+        return NULL;
+    }
     ret = str++;
     while (*str && !strchr( delim, *str )) str++;
     if (*str) *str++ = 0;
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 6bf3b6e775d..be0356f4c7e 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -1685,6 +1685,14 @@ static void test_strtok(void)
                 "third call string (%p) \'%s\' return %p\n",
                 teststr, testcases_strtok[i].string, strret);
     }
+
+    strcpy( teststr, "test a=b" );
+    strret = strtok( teststr, " " );
+    ok( strret == teststr, "strret = %p, expected %p\n", strret, teststr );
+    strret = strtok( NULL, "ab=" );
+    ok( !strret, "strret = %p, expected NULL\n", strret );
+    strret = strtok( NULL, "=" );
+    ok( !strret, "strret = %p, expected NULL\n", strret );
 }
 
 static void test_strtol(void)




More information about the wine-cvs mailing list