From 59ab240ce293d9d9526747b6c25b0bf8925f1dbc Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Mon, 3 Feb 2020 12:06:10 -0800 Subject: [PATCH v5 1/2] msvcrt: Don't set error in wcstombs_s_l if no characters to convert. Signed-off-by: Daniel Lehman --- v5: - check !tmp v4: - fix handling of return from WideCharToMultiByte v3: - fix empty string case --- dlls/msvcrt/tests/string.c | 2 +- dlls/msvcrt/wcs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 32e264908ae..7d9b46b3e6f 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -2300,7 +2300,7 @@ static void test__wcstombs_s_l(void) { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, NULL, FALSE, TRUE }, { L"text", 5, "", 3, 0, ERANGE, NULL, TRUE }, - { L"", 0, NULL, 0, 1, 0, "English_United States.1252", TRUE, TRUE }, + { L"", 0, NULL, 0, 1, 0, "English_United States.1252" }, { L"\xfffd", 1, NULL, 0, 0, EILSEQ, "English_United States.1252", TRUE }, { L"\xfffd", 1, "", 1, 0, EILSEQ, "English_United States.1252", TRUE }, { L"\xfffd", 1, "", 6, 0, EILSEQ, "English_United States.1252", TRUE }, diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 84110482046..64bc1f83d47 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -459,12 +459,12 @@ static MSVCRT_size_t MSVCRT_wcsrtombs_l(char *mbstr, const MSVCRT_wchar_t **wcst if(!mbstr) { tmp = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, - *wcstr, -1, NULL, 0, NULL, &used_default)-1; + *wcstr, -1, NULL, 0, NULL, &used_default); if(!tmp || used_default) { *MSVCRT__errno() = MSVCRT_EILSEQ; return -1; } - return tmp; + return tmp-1; } while(**wcstr) { -- 2.17.0