Piotr Caban : msvcrt: Fix mbtowc behavior for buffers containing more than one character.

Alexandre Julliard julliard at winehq.org
Mon Aug 22 07:32:37 CDT 2016


Module: wine
Branch: stable
Commit: ab49e20fbf80274f0b41e60a48e7a3978404c207
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ab49e20fbf80274f0b41e60a48e7a3978404c207

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Fri May  6 22:09:14 2016 +0200

msvcrt: Fix mbtowc behavior for buffers containing more than one character.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit a36b5f0741ac7e6a44aaa9d804ebdb7524186723)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/msvcrt/mbcs.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index c206af1..3b27b9d 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -2154,17 +2154,25 @@ int CDECL MSVCRT_mbtowc_l(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n,
 
     if(n <= 0 || !str)
         return 0;
-    if(!locinfo->lc_codepage)
-        tmpdst = (unsigned char)*str;
-    else if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, n, &tmpdst, 1))
-        return -1;
-    if(dst)
-        *dst = tmpdst;
-    /* return the number of bytes from src that have been used */
-    if(!*str)
+
+    if(!*str) {
+        if(dst) *dst = 0;
         return 0;
-    if(n >= 2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale) && str[1])
+    }
+
+    if(!locinfo->lc_codepage) {
+        if(dst) *dst = (unsigned char)*str;
+        return 1;
+    }
+    if(n>=2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale)) {
+        if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 2, &tmpdst, 1))
+            return -1;
+        if(dst) *dst = tmpdst;
         return 2;
+    }
+    if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 1, &tmpdst, 1))
+        return -1;
+    if(dst) *dst = tmpdst;
     return 1;
 }
 




More information about the wine-cvs mailing list