From 2979afe06d944d9d92f5be64fd303088444514ec Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Fri, 10 Jan 2020 10:56:19 -0800 Subject: [PATCH 3/3] msvcrt: Set return value on all paths in wcstombs_s_l. Signed-off-by: Daniel Lehman --- dlls/msvcrt/tests/string.c | 20 ++++++++------------ dlls/msvcrt/wcs.c | 16 +++++++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 994f62d4d8f..3aaef69d230 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -2288,25 +2288,23 @@ static void test__wcstombs_s_l(void) size_t ret; int err; const char *locale; - BOOL todo_ret; - BOOL todo_err; } tests[] = { /* wstr str ret err locale */ { L"", 0, NULL, 0, 1, 0, NULL }, { L"\xfffd", 1, NULL, 0, 2, 0, NULL }, - { L"\xfffd", 1, "", 1, 0, EILSEQ, NULL, TRUE }, - { L"\xfffd", 1, "", 6, 0, EILSEQ, NULL, TRUE }, + { L"\xfffd", 1, "", 1, 0, EILSEQ, NULL }, + { L"\xfffd", 1, "", 6, 0, EILSEQ, NULL }, { L"text", _TRUNCATE, "text", 5, 5, 0, NULL }, - { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, NULL, FALSE, TRUE }, - { L"text", 5, "", 3, 0, ERANGE, NULL, TRUE }, + { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, NULL }, + { L"text", 5, "", 3, 0, ERANGE, NULL }, { L"", 0, NULL, 0, 1, 0, "English.1252" }, { L"\xfffd", 1, NULL, 0, 2, 0, "English.1252" }, - { L"\xfffd", 1, "", 1, 0, EILSEQ, "English.1252", TRUE }, - { L"\xfffd", 1, "", 6, 0, EILSEQ, "English.1252", TRUE }, + { L"\xfffd", 1, "", 1, 0, EILSEQ, "English.1252" }, + { L"\xfffd", 1, "", 6, 0, EILSEQ, "English.1252" }, { L"text", _TRUNCATE, "text", 5, 5, 0, "English.1252" }, - { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, "English.1252", FALSE, TRUE }, - { L"text", 5, "", 3, 0, ERANGE, "English.1252", TRUE }, + { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, "English.1252" }, + { L"text", 5, "", 3, 0, ERANGE, "English.1252" }, }; _locale_t locale; char out[6]; @@ -2327,10 +2325,8 @@ static void test__wcstombs_s_l(void) memset(out, 0xcc, sizeof(out)); err = p_wcstombs_s_l(&ret, tests[i].str ? out : NULL, tests[i].len, tests[i].wstr, tests[i].wlen, locale); - todo_wine_if(tests[i].todo_ret) ok(ret == tests[i].ret, "%d: expected ret %d, got %d for '%s' in locale %s\n", i, tests[i].ret, ret, wine_dbgstr_w(tests[i].wstr), tests[i].locale); - todo_wine_if(tests[i].todo_err) ok(err == tests[i].err, "%d: expected err %d, got %d for '%s' in locale %s\n", i, tests[i].err, err, wine_dbgstr_w(tests[i].wstr), tests[i].locale); if(tests[i].str) diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 3b7bd5e0728..928600fe32f 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -532,6 +532,7 @@ static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t *ret, char *mbstr, MSVCRT_size_t count, MSVCRT__locale_t locale) { MSVCRT_size_t conv; + int err; if(!mbstr && !size && wcstr) { conv = MSVCRT_wcsrtombs_l(NULL, wcstr, 0, locale); @@ -552,25 +553,30 @@ static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t *ret, char *mbstr, else conv = count; + err = 0; conv = MSVCRT_wcsrtombs_l(mbstr, wcstr, conv, locale); if(conv == -1) { + conv = 0; if(size) mbstr[0] = '\0'; - return *MSVCRT__errno(); + err = *MSVCRT__errno(); }else if(conv < size) mbstr[conv++] = '\0'; - else if(conv==size && (count==MSVCRT__TRUNCATE || mbstr[conv-1]=='\0')) + else if(conv==size && (count==MSVCRT__TRUNCATE || mbstr[conv-1]=='\0')) { mbstr[conv-1] = '\0'; - else { + if(count==MSVCRT__TRUNCATE) + err = MSVCRT_STRUNCATE; + }else { MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE); + conv = 0; if(size) mbstr[0] = '\0'; - return MSVCRT_ERANGE; + err = MSVCRT_ERANGE; } if(ret) *ret = conv; - return 0; + return err; } /********************************************************************* -- 2.17.0