[PATCH v6 1/5] itss: Fix handling of UTF-8 strings.

Matteo Bruni mbruni at codeweavers.com
Tue Sep 12 14:22:27 CDT 2017


From: Rafał Mużyło <galtgendo at o2.pl>

Signed-off-by: Rafał Mużyło <galtgendo at o2.pl>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
This version adds a cast to avoid a compilation warning and handles
0-length strings (which I don't know if they are possible in the first
place). Feel free to use or ignore it at your discretion.

 dlls/itss/chm_lib.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/dlls/itss/chm_lib.c b/dlls/itss/chm_lib.c
index f2586233bd..676e33d71c 100644
--- a/dlls/itss/chm_lib.c
+++ b/dlls/itss/chm_lib.c
@@ -935,14 +935,19 @@ static UInt64 _chm_parse_cword(UChar **pEntry)
 /* parse a utf-8 string into an ASCII char buffer */
 static BOOL _chm_parse_UTF8(UChar **pEntry, UInt64 count, WCHAR *path)
 {
-    /* MJM - Modified to return real Unicode strings */ 
-    while (count != 0)
+    unsigned int ret;
+
+    if (!count)
     {
-        *path++ = (*(*pEntry)++);
-        --count;
+        path[0] = '\0';
+        return TRUE;
     }
 
-    *path = '\0';
+    ret = MultiByteToWideChar(CP_UTF8, 0, (const char *)*pEntry, count, path, CHM_MAX_PATHLEN);
+    *pEntry += count;
+    if (!ret)
+        return FALSE;
+    path[ret] = '\0';
     return TRUE;
 }
 
-- 
2.13.5




More information about the wine-patches mailing list