msvcrt: Set next_token when str is empty in wcstok_s.

Otherwise, when str is empty, an invalid parameter exception is raised.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=30244
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-05-25 15:59:46 +02:00 committed by Alexandre Julliard
parent 6c39e731f4
commit 32bbef5d3e
2 changed files with 25 additions and 4 deletions

View File

@ -1910,10 +1910,13 @@ wchar_t * CDECL wcstok_s( wchar_t *str, const wchar_t *delim,
if (!str) str = *next_token;
while (*str && wcschr( delim, *str )) str++;
if (!*str) return NULL;
ret = str++;
while (*str && !wcschr( delim, *str )) str++;
if (*str) *str++ = 0;
if (!*str) ret = NULL;
else
{
ret = str++;
while (*str && !wcschr( delim, *str )) str++;
if (*str) *str++ = 0;
}
*next_token = str;
return ret;
}

View File

@ -418,6 +418,24 @@ static void test_wcstok(void)
ok(!wcscmp(L"words", token), "expected \"words\", got \"%ls\"\n", token);
token = wcstok(NULL, L" ", NULL);
ok(!token, "expected NULL, got %p\n", token);
next = NULL;
wcscpy(buffer, input);
token = wcstok(buffer, L"=", &next);
ok(!wcscmp(token, input), "expected \"%ls\", got \"%ls\"\n", input, token);
ok(next == buffer + wcslen(input), "expected %p, got %p\n", buffer + wcslen(input), next);
token = wcstok(NULL, L"=", &next);
ok(!token, "expected NULL, got \"%ls\"\n", token);
ok(next == buffer + wcslen(input), "expected %p, got %p\n", buffer + wcslen(input), next);
next = NULL;
wcscpy(buffer, L"");
token = wcstok(buffer, L"=", &next);
ok(token == NULL, "expected NULL, got \"%ls\"\n", token);
ok(next == buffer, "expected %p, got %p\n", buffer, next);
token = wcstok(NULL, L"=", &next);
ok(!token, "expected NULL, got \"%ls\"\n", token);
ok(next == buffer, "expected %p, got %p\n", buffer, next);
}
static void test__strnicmp(void)