lib: Fix double byte default char initialization

Nikolay Sivov nsivov at codeweavers.com
Tue Sep 8 15:49:34 CDT 2015


For https://bugs.winehq.org/show_bug.cgi?id=32582

Existing init expression seems to break whenever first or second byte 
has msb set.
-------------- next part --------------
From d9502fbb0515d5724d23fbd41bfedebfced37da5 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Tue, 8 Sep 2015 23:45:20 +0300
Subject: [PATCH] lib: Fix double byte default char initialization

---
 dlls/kernel32/tests/codepage.c | 9 ++++++++-
 libs/wine/wctomb.c             | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/tests/codepage.c b/dlls/kernel32/tests/codepage.c
index 71bedb7..54f62ae 100644
--- a/dlls/kernel32/tests/codepage.c
+++ b/dlls/kernel32/tests/codepage.c
@@ -276,12 +276,14 @@ static void test_overlapped_buffers(void)
 static void test_string_conversion(LPBOOL bUsedDefaultChar)
 {
     char mbc;
-    char mbs[5];
+    char mbs[15];
     int ret;
     WCHAR wc1 = 228;                           /* Western Windows-1252 character */
     WCHAR wc2 = 1088;                          /* Russian Windows-1251 character not displayable for Windows-1252 */
     static const WCHAR wcs[] = {'T', 'h', 1088, 'i', 0}; /* String with ASCII characters and a Russian character */
     static const WCHAR dbwcs[] = {28953, 25152, 0}; /* String with Chinese (codepage 950) characters */
+    static const WCHAR dbwcs2[] = {0x7bb8, 0x3d, 0xc813, 0xac00, 0xb77d, 0};
+    static const char default_char[] = {0xa3, 0xbf, 0};
 
     SetLastError(0xdeadbeef);
     ret = WideCharToMultiByte(1252, 0, &wc1, 1, &mbc, 1, NULL, bUsedDefaultChar);
@@ -358,6 +360,11 @@ static void test_string_conversion(LPBOOL bUsedDefaultChar)
     ok(!strcmp(mbs, "??"), "mbs is %s\n", mbs);
     if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
 
+    ret = WideCharToMultiByte(936, WC_COMPOSITECHECK, dbwcs2, -1, mbs, sizeof(mbs), (const char *)default_char, bUsedDefaultChar);
+    ok(ret == 10, "ret is %d\n", ret);
+    ok(!strcmp(mbs, "\xf3\xe7\x3d\xa3\xbf\xa3\xbf\xa3\xbf"), "mbs is %s\n", mbs);
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar == TRUE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
+
     /* Length-only tests */
     SetLastError(0xdeadbeef);
     ret = WideCharToMultiByte(1252, 0, &wc2, 1, NULL, 0, NULL, bUsedDefaultChar);
diff --git a/libs/wine/wctomb.c b/libs/wine/wctomb.c
index 3b081d4..5a24faf 100644
--- a/libs/wine/wctomb.c
+++ b/libs/wine/wctomb.c
@@ -380,7 +380,7 @@ static int wcstombs_dbcs_slow( const struct dbcs_table *table, int flags,
     WCHAR composed;
     int len, tmp;
 
-    if (defchar) defchar_value = defchar[1] ? ((defchar[0] << 8) | defchar[1]) : defchar[0];
+    if (defchar) defchar_value = defchar[1] ? ((defchar[0] << 8) & 0xff00 | (defchar[1] & 0xff)) : defchar[0];
     if (!used) used = &tmp;  /* avoid checking on every char */
     *used = 0;
 
-- 
2.1.4



More information about the wine-patches mailing list