Commit 5983fcfe authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Return error on invalid character in mbstowcs.

parent 93bf951e
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment