JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Work around dmenu version incompatibilities.
authorThordur Bjornsson <thib@secnorth.net>
Tue, 29 Nov 2011 23:39:31 +0000 (23:39 +0000)
committerThordur Bjornsson <thib@secnorth.net>
Tue, 29 Nov 2011 23:59:13 +0000 (23:59 +0000)
Older versions of dmenu (4.2.1) do not send the newline character
long with the response while newer versions (4.4.2) do, this
causes mild bugs (last char in the name of the workspace gets
lobbed off for example). Fix it by sanitizing the string in the
response handler.

Tested by me & lteo with different dmenu version.
OK lteo, marco

scrotwm.c

index 718c5d5..48ddf00 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -3452,7 +3452,6 @@ search_resp_name_workspace(char *resp, unsigned long len)
                            strerror(errno));
                        return;
                }
                            strerror(errno));
                        return;
                }
-               ws->name[len - 1] = '\0';
        }
 }
 
        }
 }
 
@@ -3472,7 +3471,6 @@ search_resp_search_workspace(char *resp, unsigned long len)
                    strerror(errno));
                return;
        }
                    strerror(errno));
                return;
        }
-       q[len - 1] = '\0';
        p = strchr(q, ':');
        if (p != NULL)
                *p = '\0';
        p = strchr(q, ':');
        if (p != NULL)
                *p = '\0';
@@ -3504,7 +3502,7 @@ search_resp_search_window(char *resp, unsigned long len)
                    strerror(errno));
                return;
        }
                    strerror(errno));
                return;
        }
-       s[len - 1] = '\0';
+
        idx = strtonum(s, 1, INT_MAX, &errstr);
        if (errstr) {
                DNPRINTF(SWM_D_MISC, "window idx is %s: %s",
        idx = strtonum(s, 1, INT_MAX, &errstr);
        if (errstr) {
                DNPRINTF(SWM_D_MISC, "window idx is %s: %s",
@@ -3546,6 +3544,12 @@ search_do_resp(void)
                goto done;
        }
        resp[rbytes] = '\0';
                goto done;
        }
        resp[rbytes] = '\0';
+
+       /* XXX:
+        * Older versions of dmenu (Atleast pre 4.4.1) do not send a
+        * newline, so work around that by sanitizing the resp now.
+        */
+       resp[strcspn(resp, "\n")] = '\0';
        len = strlen(resp);
 
        switch (search_resp_action) {
        len = strlen(resp);
 
        switch (search_resp_action) {