From a845084397af21f64d9731134f4f750f2d16e0e7 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Mon, 3 Feb 2020 12:14:11 -0800 Subject: [PATCH v3 3/3] msvcrt: Set return value on all paths in wcstombs_s_l. Signed-off-by: Daniel Lehman --- v3: - fix case #8 --- dlls/msvcrt/tests/string.c | 22 +++++++++------------- dlls/msvcrt/wcs.c | 20 +++++++++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 7d9b46b3e6f..29a8958b814 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_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 }, + { L"\xfffd", 1, NULL, 0, 0, EILSEQ, "English_United States.1252" }, + { L"\xfffd", 1, "", 1, 0, EILSEQ, "English_United States.1252" }, + { L"\xfffd", 1, "", 6, 0, EILSEQ, "English_United States.1252" }, { L"text", _TRUNCATE, "text", 5, 5, 0, "English_United States.1252" }, - { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, "English_United States.1252", FALSE, TRUE }, - { L"text", 5, "", 3, 0, ERANGE, "English_United States.1252", TRUE }, + { L"text", _TRUNCATE, "", 1, 1, STRUNCATE, "English_United States.1252" }, + { L"text", 5, "", 3, 0, ERANGE, "English_United States.1252" }, }; _locale_t locale; char out[6]; @@ -2333,10 +2331,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 5710fe85e02..3ce0ec0d465 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -532,13 +532,14 @@ 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); - if(conv == -1) - return *MSVCRT__errno(); if(ret) *ret = conv+1; + if(conv == -1) + return *MSVCRT__errno(); return 0; } @@ -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