Akihiro Sagawa : msvcrt: Add validity checks for _mbstrlen_l.

Alexandre Julliard julliard at winehq.org
Thu Dec 1 14:05:33 CST 2011


Module: wine
Branch: master
Commit: 28184600e74972c0cc5268c79e2b22da3643ac6c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=28184600e74972c0cc5268c79e2b22da3643ac6c

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Wed Nov 30 22:34:09 2011 +0900

msvcrt: Add validity checks for _mbstrlen_l.

---

 dlls/msvcrt/mbcs.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index ac45881..a8cd237 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -1858,15 +1858,14 @@ MSVCRT_size_t CDECL _mbstrlen_l(const char* str, MSVCRT__locale_t locale)
         locinfo = locale->locinfo;
 
     if(locinfo->mb_cur_max > 1) {
-        MSVCRT_size_t len = 0;
-        while(*str) {
-            /* FIXME: According to the documentation we are supposed to test for
-             * multi-byte character validity. Whatever that means
-             */
-            str += MSVCRT_isleadbyte(*str) ? 2 : 1;
-            len++;
+        MSVCRT_size_t len;
+        len = MultiByteToWideChar(locinfo->lc_codepage, MB_ERR_INVALID_CHARS,
+                                  str, -1, NULL, 0);
+        if (!len) {
+            *MSVCRT__errno() = MSVCRT_EILSEQ;
+            return -1;
         }
-        return len;
+        return len - 1;
     }
 
     return strlen(str);




More information about the wine-cvs mailing list