Piotr Caban : msvcr110: Copy utf16 strings in _Gettnames.

Alexandre Julliard julliard at winehq.org
Tue Feb 2 15:52:10 CST 2021


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Feb  2 18:55:33 2021 +0100

msvcr110: Copy utf16 strings in _Gettnames.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50409
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcr120/tests/msvcr120.c | 13 ++++++++++---
 dlls/msvcrt/locale.c           | 12 ++++++++++++
 dlls/msvcrt/tests/locale.c     |  4 ++++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcr120/tests/msvcr120.c b/dlls/msvcr120/tests/msvcr120.c
index 5976a86963a..a68870ac77b 100644
--- a/dlls/msvcr120/tests/msvcr120.c
+++ b/dlls/msvcr120/tests/msvcr120.c
@@ -171,6 +171,7 @@ static int (__cdecl *p__dpcomp)(double x, double y);
 static wchar_t** (CDECL *p____lc_locale_name_func)(void);
 static unsigned int (CDECL *p__GetConcurrency)(void);
 static void* (CDECL *p__W_Gettnames)(void);
+static void* (CDECL *p__Gettnames)(void);
 static void (CDECL *p_free)(void*);
 static float (CDECL *p_strtof)(const char *, char **);
 static int (CDECL *p__finite)(double);
@@ -242,6 +243,7 @@ static BOOL init(void)
     p____lc_locale_name_func = (void*)GetProcAddress(module, "___lc_locale_name_func");
     p__GetConcurrency = (void*)GetProcAddress(module,"?_GetConcurrency at details@Concurrency@@YAIXZ");
     p__W_Gettnames = (void*)GetProcAddress(module, "_W_Gettnames");
+    p__Gettnames = (void*)GetProcAddress(module, "_Gettnames");
     p_free = (void*)GetProcAddress(module, "free");
     p_strtof = (void*)GetProcAddress(module, "strtof");
     p__finite = (void*)GetProcAddress(module, "_finite");
@@ -531,7 +533,7 @@ static void test__GetConcurrency(void)
     ok(c == si.dwNumberOfProcessors, "expected %u, got %u\n", si.dwNumberOfProcessors, c);
 }
 
-static void test__W_Gettnames(void)
+static void test_gettnames(void* (CDECL *p_gettnames)(void))
 {
     static const char *str[] = {
         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
@@ -557,7 +559,7 @@ static void test__W_Gettnames(void)
     if(!p_setlocale(LC_ALL, "english"))
         return;
 
-    ret = p__W_Gettnames();
+    ret = p_gettnames();
     size = ret->str[0]-(char*)ret;
     if(sizeof(void*) == 8)
         ok(size==0x2c0, "structure size: %x\n", size);
@@ -572,6 +574,10 @@ static void test__W_Gettnames(void)
         ok(!lstrcmpW(ret->wstr[i], buf), "ret->wstr[%d] = %s, expected %s\n",
                 i, wine_dbgstr_w(ret->wstr[i]), wine_dbgstr_w(buf));
     }
+
+    ok(ret->str[42] + strlen(ret->str[42])+1 == (char*)ret->wstr[0],
+            "ret->str[42] = %p len = %d, ret->wstr[0] = %p\n",
+            ret->str[42], strlen(ret->str[42]), ret->wstr[0]);
     p_free(ret);
 
     p_setlocale(LC_ALL, "C");
@@ -1111,7 +1117,8 @@ START_TEST(msvcr120)
     test__dpcomp();
     test____lc_locale_name_func();
     test__GetConcurrency();
-    test__W_Gettnames();
+    test_gettnames(p__W_Gettnames);
+    test_gettnames(p__Gettnames);
     test__strtof();
     test_remainder();
     test_critical_section();
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 79a8d47d6d5..5a4a701dfc6 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -804,6 +804,10 @@ void* CDECL _Gettnames(void)
 
     for(i=0; i<ARRAY_SIZE(cur->str.str); i++)
         size += strlen(cur->str.str[i])+1;
+#if _MSVCR_VER >= 110
+    for(i=0; i<ARRAY_SIZE(cur->wstr.wstr); i++)
+        size += (wcslen(cur->wstr.wstr[i]) + 1) * sizeof(wchar_t);
+#endif
 
     ret = malloc(size);
     if(!ret)
@@ -817,6 +821,14 @@ void* CDECL _Gettnames(void)
         ret->str.str[i] = &ret->data[size];
         size += len;
     }
+#if _MSVCR_VER >= 110
+    for(i=0; i<ARRAY_SIZE(cur->wstr.wstr); i++) {
+        len = (wcslen(cur->wstr.wstr[i]) + 1) * sizeof(wchar_t);
+        memcpy(&ret->data[size], cur->wstr.wstr[i], len);
+        ret->wstr.wstr[i] = (wchar_t*)&ret->data[size];
+        size += len;
+    }
+#endif
 
     return ret;
 }
diff --git a/dlls/msvcrt/tests/locale.c b/dlls/msvcrt/tests/locale.c
index 176e3b5e6e4..030d65de3cb 100644
--- a/dlls/msvcrt/tests/locale.c
+++ b/dlls/msvcrt/tests/locale.c
@@ -733,6 +733,10 @@ static void test__Gettnames(void)
         ok(!strcmp(ret->str[i], buf), "ret->str[%i] = %s, expected %s\n", i, ret->str[i], buf);
     }
 
+    ok(ret->wstr[0] != NULL, "ret->wstr[0] = NULL\n");
+    ok(ret->str[42] + strlen(ret->str[42])+1 != (char*)ret->wstr[0],
+            "ret->str[42] = %p len = %d, ret->wstr[0] = %p\n",
+            ret->str[42], strlen(ret->str[42]), ret->wstr[0]);
     free(ret);
 
     if(!setlocale(LC_TIME, "german"))




More information about the wine-cvs mailing list