From 8c23f0b8fb067205e557d21aadf2bcfe6205bb89 Mon Sep 17 00:00:00 2001
From: tatyana <tatyana@etersoft.ru>
Date: Wed, 9 Jan 2013 16:09:21 +0400
Subject: [PATCH 2/2] kernel32: MBTWC called with StaticUnicodeBuffer only if
 size of strings <=130

---
 dlls/kernel32/locale.c       | 61 +++++++++++++++++++-------------------------
 dlls/kernel32/tests/locale.c |  1 -
 2 files changed, 26 insertions(+), 36 deletions(-)

diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 57daab1..e2a684c 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -2993,51 +2993,42 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
 
     if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
 
-    if (len1)
+    if(len1 <= 130)
     {
-        len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
-        if (len1W)
-            str1W = buf1W;
-        else
-        {
-            len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
-            str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
-            if (!str1W)
-            {
-                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-                return 0;
-            }
-            MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
-        }
+        if(len1)
+            len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
+        else len1W=0;
+        str1W = buf1W;
     }
     else
     {
-        len1W = 0;
-        str1W = buf1W;
+        len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
+        str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
+        if (!str1W)
+        {
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return 0;
+        }
+        MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
     }
 
-    if (len2)
+    if(len2 <= 130)
     {
-        len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
-        if (len2W)
-            str2W = buf2W;
-        else
-        {
-            len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
-            str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
-            if (!str2W)
-            {
-                if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
-                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-                return 0;
-            }
-            MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
-        }
+        if(len2)
+            len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
+        else len2W=0;
+        str2W = buf2W;
     }
     else
     {
-        len2W = 0;
-        str2W = buf2W;
+        len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
+        str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
+        if (!str2W)
+        {
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return 0;
+        }
+        MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
     }
 
     ret = CompareStringEx(NULL, flags, str1W, len1W, str2W, len2W, NULL, NULL, 0);
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index fc902be..6275b2a 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -1454,7 +1454,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.0.3
