msvcrt: Return error on invalid character in mbstowcs.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-08-05 15:07:18 +02:00 committed by Alexandre Julliard
parent 93bf951e1c
commit 5983fcfec9
2 changed files with 16 additions and 4 deletions

View File

@ -2472,8 +2472,15 @@ MSVCRT_size_t CDECL MSVCRT__mbstowcs_l(MSVCRT_wchar_t *wcstr, const char *mbstr,
}
/* Ignore count parameter */
if(!wcstr)
return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
if(!wcstr) {
size = MultiByteToWideChar(locinfo->lc_codepage,
MB_ERR_INVALID_CHARS, mbstr, -1, NULL, 0);
if(!size) {
*MSVCRT__errno() = MSVCRT_EILSEQ;
return -1;
}
return size - 1;
}
for(i=0, size=0; i<count; i++) {
if(mbstr[size] == '\0')
@ -2483,8 +2490,8 @@ MSVCRT_size_t CDECL MSVCRT__mbstowcs_l(MSVCRT_wchar_t *wcstr, const char *mbstr,
}
if(size) {
size = MultiByteToWideChar(locinfo->lc_codepage, 0,
mbstr, size, wcstr, count);
size = MultiByteToWideChar(locinfo->lc_codepage,
MB_ERR_INVALID_CHARS, mbstr, size, wcstr, count);
if(!size) {
if(count) wcstr[0] = '\0';
*MSVCRT__errno() = MSVCRT_EILSEQ;

View File

@ -2107,6 +2107,11 @@ static void test_mbstowcs(void)
ok(ret == 0, "mbstowcs did not return 0, got %d\n", (int)ret);
ok(!memcmp(wOut, wEmpty, sizeof(wEmpty)), "wOut = %s\n", wine_dbgstr_w(wOut));
errno = 0xdeadbeef;
ret = mbstowcs(wOut, mHiragana+1, 5);
ok(ret == -1, "mbstowcs did not return -1\n");
ok(errno == EILSEQ, "errno = %d\n", errno);
ret = wcstombs(mOut, wHiragana, 6);
ok(ret == 4, "wcstombs did not return 4\n");
ok(!memcmp(mOut, mHiragana, sizeof(mHiragana)), "mOut = %s\n", mOut);