If XBufferOverflow occuers, the client should recall the function with
the same event and a buffer of adequate size to obtain the string.
Fixed as such.
---
 x.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/x.c b/x.c
index d73152b..b69523d 100644
--- a/x.c
+++ b/x.c
@@ -1843,21 +1843,29 @@ kpress(XEvent *ev)
 {
        XKeyEvent *e = &ev->xkey;
        KeySym ksym = NoSymbol;
-       char buf[64], *customkey;
+       char *customkey;
+       static char *buf = NULL;
+       static int bufsize = 64;
        int len;
        Rune c;
        Status status;
        Shortcut *bp;
 
+       if (!buf)
+               buf = xmalloc(bufsize * sizeof(char));
+
        if (IS_SET(MODE_KBDLOCK))
                return;
 
        if (xw.ime.xic) {
-               len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, 
&status);
-               if (status == XBufferOverflow)
-                       return;
+               len = XmbLookupString(xw.ime.xic, e, buf, bufsize, &ksym, 
&status);
+               if (status == XBufferOverflow) {
+                       bufsize = len;
+                       buf = xrealloc(buf, bufsize * sizeof(char));
+                       XmbLookupString(xw.ime.xic, e, buf, bufsize, &ksym, 
&status);
+               }
        } else {
-               len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
+               len = XLookupString(e, buf, bufsize, &ksym, NULL);
        }
        /* 1. shortcuts */
        for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
-- 
2.49.0


Reply via email to