From d69ddda5ff20195964be17ca98db5c937b5d5a5a Mon Sep 17 00:00:00 2001
From: tatyana <tatyana@etersoft.ru>
Date: Mon, 1 Apr 2013 19:12:15 +0400
Subject: [PATCH 2/2] kernel32: MBTWC called with StaticUnicodeBuffer only if
 size of strings <=130

---
 dlls/kernel32/locale.c       | 8 +++++---
 dlls/kernel32/tests/locale.c | 1 -
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 04fb6e8..a59dbdc 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -2980,7 +2980,7 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
     WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
     WCHAR *buf2W = buf1W + 130;
     LPWSTR str1W, str2W;
-    INT len1W, len2W, ret;
+    INT len1W = 0, len2W = 0, ret;
     UINT locale_cp = CP_ACP;
 
     if (!str1 || !str2)
@@ -2995,7 +2995,8 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
 
     if (len1)
     {
-        len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
+        if (len1 <= 130)
+            len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
         if (len1W)
             str1W = buf1W;
         else
@@ -3018,7 +3019,8 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
 
     if (len2)
     {
-        len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
+        if (len2 <= 130)
+            len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
         if (len2W)
             str2W = buf2W;
         else
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index 8d4a09b..38c24fb 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -1466,7 +1466,6 @@ static void test_CompareStringA(void)
     memset(a, 'a', sizeof(a));
     SetLastError(0xdeadbeef);
     ret = CompareStringA(lcid, 0, a, sizeof(a), a, sizeof(a));
-    todo_wine
     ok (GetLastError() == 0xdeadbeef && ret == CSTR_EQUAL,
         "ret %d (expected %d), error %d\n", ret, CSTR_EQUAL, GetLastError());
 }
-- 
1.8.1.5
