Akihiro Sagawa : vbscript: Support non-Latin 1 characters in Asc.

Alexandre Julliard julliard at winehq.org
Wed Sep 16 15:37:34 CDT 2020


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

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Wed Sep 16 21:34:13 2020 +0900

vbscript: Support non-Latin 1 characters in Asc.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49309
Signed-off-by: Akihiro Sagawa <sagawa.aki at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/vbscript/global.c      | 23 ++++++++++++++++++++---
 dlls/vbscript/tests/api.vbs |  5 +++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index 80323fe136..92288fcd88 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -1749,10 +1749,27 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA
         str = conv_str;
     }
 
-    if(!SysStringLen(str) || *str >= 0x100)
+    if(!SysStringLen(str))
         hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
-    else if(res)
-        hres = return_short(res, *str);
+    else {
+        unsigned char buf[2];
+        short val = 0;
+        int n = WideCharToMultiByte(CP_ACP, 0, str, 1, (char*)buf, sizeof(buf), NULL, NULL);
+        switch(n) {
+        case 1:
+            val = buf[0];
+            break;
+        case 2:
+            val = (buf[0] << 8) | buf[1];
+            break;
+        default:
+            WARN("Failed to convert %x\n", *str);
+            hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
+        }
+        if(SUCCEEDED(hres))
+            hres = return_short(res, val);
+    }
+
     SysFreeString(conv_str);
     return hres;
 }
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index be95aae4b9..48b263334c 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -1842,6 +1842,11 @@ call testAsc("   ", 32)
 call testAsc(Chr(255), 255)
 call testAsc(Chr(0), 0)
 if isEnglishLang then testAsc true, 84
+if Asc(Chr(&h81)) = &h8145 then
+    ' Japanese (CP 932)
+    call testAsc(Chr(&h8e8e), -29042)
+    call testAsc(Chr(220), 220)
+end if
 call testAscError()
 
 sub testErrNumber(n)




More information about the wine-cvs mailing list