diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index a065b8b003b..dc52cf1b8cf 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -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; ilc_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; diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 3970f703f65..a4b1fb9d11d 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -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);