winex11.drv: Handle arbitrary length composed input. [take 2]

Kusanagi Kouichi slash at ma.neweb.ne.jp
Thu Mar 20 14:53:27 CDT 2008


Use HeapAlloc() to allocate buffer.

Fix bug #9838. http://bugs.winehq.org/show_bug.cgi?id=9838
---
 dlls/winex11.drv/keyboard.c |   30 +++++++++++++++++++++---------
 dlls/winex11.drv/xim.c      |   19 +++++++++++++------
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c
index 33640db..4c21335 100644
--- a/dlls/winex11.drv/keyboard.c
+++ b/dlls/winex11.drv/keyboard.c
@@ -1365,22 +1365,34 @@ void X11DRV_KeyEvent( HWND hwnd, XEvent *xev )
     wine_tsx11_lock();
     /* Clients should pass only KeyPress events to XmbLookupString */
     if (xic && event->type == KeyPress)
+    {
         ascii_chars = XmbLookupString(xic, event, Str, sizeof(Str), &keysym, &status);
+
+        if (status == XBufferOverflow)
+        {
+            char *buf;
+
+            buf = HeapAlloc(GetProcessHeap(), 0, ascii_chars);
+            if (buf)
+            {
+                ascii_chars = XmbLookupString(xic, event, buf, ascii_chars, &keysym, &status);
+                X11DRV_XIMLookupChars( buf, ascii_chars );
+                HeapFree(GetProcessHeap(), 0, buf);
+            }
+            return;
+        }
+        else if (status == XLookupChars)
+        {
+            X11DRV_XIMLookupChars( Str, ascii_chars );
+            return;
+        }
+    }
     else
         ascii_chars = XLookupString(event, Str, sizeof(Str), &keysym, NULL);
     wine_tsx11_unlock();
 
     TRACE_(key)("nbyte = %d, status 0x%x\n", ascii_chars, status);
 
-    if (status == XBufferOverflow)
-        ERR("Buffer Overflow need %i!\n",ascii_chars);
-
-    if (status == XLookupChars)
-    {
-        X11DRV_XIMLookupChars( Str, ascii_chars );
-        return;
-    }
-
     /* If XKB extensions are used, the state mask for AltGr will use the group
        index instead of the modifier mask. The group index is set in bits
        13-14 of the state field in the XKeyEvent structure. So if AltGr is
diff --git a/dlls/winex11.drv/xim.c b/dlls/winex11.drv/xim.c
index 4c6c6b2..053b1db 100644
--- a/dlls/winex11.drv/xim.c
+++ b/dlls/winex11.drv/xim.c
@@ -239,15 +239,22 @@ static BOOL X11DRV_ImmSetInternalString(DWORD dwIndex, DWORD dwOffset,
 void X11DRV_XIMLookupChars( const char *str, DWORD count )
 {
     DWORD dwOutput;
-    WCHAR wcOutput[64];
-    HWND focus;
+    WCHAR *wcOutput;
 
-    dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, wcOutput, sizeof(wcOutput)/sizeof(WCHAR));
+    dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, NULL, 0);
+    wcOutput = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR) * dwOutput);
+    if (wcOutput)
+    {
+        HWND focus;
+
+        dwOutput = MultiByteToWideChar(CP_UNIXCP, 0, str, count, wcOutput, dwOutput);
 
-    if (pImmAssociateContext && (focus = GetFocus()))
-        pImmAssociateContext(focus,root_context);
+        if (pImmAssociateContext && (focus = GetFocus()))
+            pImmAssociateContext(focus, root_context);
 
-    X11DRV_ImmSetInternalString(GCS_RESULTSTR,0,0,wcOutput,dwOutput);
+        X11DRV_ImmSetInternalString(GCS_RESULTSTR, 0, 0, wcOutput, dwOutput);
+        HeapFree(GetProcessHeap(), 0, wcOutput);
+    }
 }
 
 static void X11DRV_ImmSetOpenStatus(BOOL fOpen)
-- 
1.5.4.4




More information about the wine-patches mailing list