Alexandre Julliard : ntdll: Don't handle the full Unicode character range in wcsicmp/wcsnicmp.

Alexandre Julliard julliard at winehq.org
Wed Mar 11 17:38:30 CDT 2020


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Mar  9 20:04:20 2020 +0100

ntdll: Don't handle the full Unicode character range in wcsicmp/wcsnicmp.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/tests/string.c | 27 +++++++++++++++++++++++++++
 dlls/ntdll/wcstring.c     | 18 ++++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c
index 1ec5f3a278..dcccb5a55f 100644
--- a/dlls/ntdll/tests/string.c
+++ b/dlls/ntdll/tests/string.c
@@ -57,6 +57,8 @@ static LPWSTR   (__cdecl *p_wcslwr)(LPWSTR);
 static LPWSTR   (__cdecl *p_wcsupr)(LPWSTR);
 static WCHAR    (__cdecl *ptowlower)(WCHAR);
 static WCHAR    (__cdecl *ptowupper)(WCHAR);
+static int      (__cdecl *p_wcsicmp)(LPCWSTR,LPCWSTR);
+static int      (__cdecl *p_wcsnicmp)(LPCWSTR,LPCWSTR,int);
 
 static LPWSTR   (__cdecl *pwcschr)(LPCWSTR, WCHAR);
 static LPWSTR   (__cdecl *pwcsrchr)(LPCWSTR, WCHAR);
@@ -102,6 +104,8 @@ static void InitFunctionPtrs(void)
     X(_wcsupr);
     X(towlower);
     X(towupper);
+    X(_wcsicmp);
+    X(_wcsnicmp);
     X(wcschr);
     X(wcsrchr);
     X(qsort);
@@ -1196,6 +1200,28 @@ static void test_wcslwrupr(void)
         ok( buffer[i - 1] == (i >= 'a' && i <= 'z' ? i - 32 : i), "%04x: got %04x\n", i, buffer[i-1] );
 }
 
+static void test_wcsicmp(void)
+{
+    WCHAR buf_a[2], buf_b[2];
+    int i, j, ret;
+
+    buf_a[1] = buf_b[1] = 0;
+    for (i = 0; i < 0x300; i++)
+    {
+        int lwr_a = (i >= 'A' && i <= 'Z') ? i + 32 : i;
+        buf_a[0] = i;
+        for (j = 0; j < 0x300; j++)
+        {
+            int lwr_b = (j >= 'A' && j <= 'Z') ? j + 32 : j;
+            buf_b[0] = j;
+            ret = p_wcsicmp( buf_a, buf_b );
+            ok( ret == lwr_a - lwr_b, "%04x:%04x: strings differ %d\n", i, j, ret );
+            ret = p_wcsnicmp( buf_a, buf_b, 2 );
+            ok( ret == lwr_a - lwr_b, "%04x:%04x: strings differ %d\n", i, j, ret );
+        }
+    }
+}
+
 static int __cdecl intcomparefunc(const void *a, const void *b)
 {
     const int *p = a, *q = b;
@@ -1567,5 +1593,6 @@ START_TEST(string)
     test_tolower();
     test_toupper();
     test__strnicmp();
+    test_wcsicmp();
     test_sscanf();
 }
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index 15a6a15531..58fc0715a7 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -38,7 +38,14 @@
  */
 INT __cdecl NTDLL__wcsicmp( LPCWSTR str1, LPCWSTR str2 )
 {
-    return strcmpiW( str1, str2 );
+    for (;;)
+    {
+        WCHAR ch1 = (*str1 >= 'A' && *str1 <= 'Z') ? *str1 + 32 : *str1;
+        WCHAR ch2 = (*str2 >= 'A' && *str2 <= 'Z') ? *str2 + 32 : *str2;
+        if (ch1 != ch2 || !*str1) return ch1 - ch2;
+        str1++;
+        str2++;
+    }
 }
 
 
@@ -64,7 +71,14 @@ LPWSTR __cdecl NTDLL__wcslwr( LPWSTR str )
  */
 INT __cdecl NTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n )
 {
-    return strncmpiW( str1, str2, n );
+    int ret = 0;
+    for ( ; n > 0; n--, str1++, str2++)
+    {
+        WCHAR ch1 = (*str1 >= 'A' && *str1 <= 'Z') ? *str1 + 32 : *str1;
+        WCHAR ch2 = (*str2 >= 'A' && *str2 <= 'Z') ? *str2 + 32 : *str2;
+        if ((ret = ch1 - ch2) ||  !*str1) break;
+    }
+    return ret;
 }
 
 




More information about the wine-cvs mailing list