Daniel Lehman : msvcrt: Set return value on all paths in wcstombs_s_l.

Alexandre Julliard julliard at winehq.org
Wed Feb 5 16:53:35 CST 2020


Module: wine
Branch: master
Commit: e9737e173825201a7ecabcc9f8487d563a7bdc50
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e9737e173825201a7ecabcc9f8487d563a7bdc50

Author: Daniel Lehman <dlehman at esri.com>
Date:   Mon Feb  3 12:14:11 2020 -0800

msvcrt: Set return value on all paths in wcstombs_s_l.

Signed-off-by: Daniel Lehman <dlehman at esri.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 7d9b46b3e6..29a8958b81 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 64bc1f83d4..cf635ed1c2 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -530,13 +530,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;
     }
 
@@ -550,25 +551,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;
 }
 
 /*********************************************************************




More information about the wine-cvs mailing list