On Tue, 26 Dec 2017 13:28:34 +0100 Kernc <kernc...@gmail.com> wrote: Hey Kernc,
> dwm 6.1-3 on ArchLinux sets WM_NAME hint on one of its windows to: > > "dwm\0" > > (with \0 being a null byte). Not certain of this, but it's what > xwininfo reports: > > $ xwininfo -root -all > Root window id: 0x126 (the root window) " X 62% | us | 59°C | > 0.31 | 3725MB | ac 100% | Dec 26 12:42 " > Parent window id: 0x0 (none) > 42 children: > ... > 0xa0001e "dwm^@": () 1x1+0+0 +0+0 > 0xa0000d (has no name): ("dwm" "dwm") 2560x19+0+0 +0+0 > ... > > (^@ is null character in caret notation.) > > This makes a particular program that uses libwnck [1] fail after: > > Wnck-WARNING **: Property _NET_WM_NAME contained invalid UTF-8 > > in this code [2] because the returned string contains a '\0' and the > documentation for g_utf8_validate() [3] explicitly states that when > string length is provided, no nul bytes are allowed. > > Maybe libwnck's atom string handling should be more robust, but > since no other window ever seems to do this, I dare ask: > > *Why* does dwm set the title on one of its windows to "dwm\0" ? first off, thank you very much for this well-written report! I'm sure everyone agrees that more should start like this; it saves everyone involved in reading a good amount of time. The problem itself seems like a trivial matter, and from what I see, we should change the constant 4 in [0] to 3. I personally don't care about libwnck to be honest, however, what convinces me is what xwininfo puts in its output. In a more philosophical sense: The NUL-byte is just a form of termination for strings in memory. When we carry around the explicit length of the string anyway, there's no reason to carry around the NUL-byte as well. Maybe it was set this way in the first place to prevent possible accidents from happening, like somebody using XGetProperty and forgetting that the given string is not NUL-terminated or something. However, I generally do not support this kind of pre-thought, as any tool containing this bug would break on any other wm which does not NUL-terminate its name in the X-property. The only thing missing from this report was a patch, which I attached. With best regards Laslo Hunhold [0]: https://git.suckless.org/dwm/tree/dwm.c#n1582 -- Laslo Hunhold <d...@frign.de>
>From 0ddcced33d85743e19f0c3d049abb93a5e03b4a6 Mon Sep 17 00:00:00 2001 From: Laslo Hunhold <d...@frign.de> Date: Tue, 26 Dec 2017 20:01:55 +0100 Subject: [PATCH] Do not explicitly include the NUL-byte in the WMName-property --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index ff893df..ec6a27c 100644 --- a/dwm.c +++ b/dwm.c @@ -1579,7 +1579,7 @@ setup(void) XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &wmcheckwin, 1); XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8, - PropModeReplace, (unsigned char *) "dwm", 4); + PropModeReplace, (unsigned char *) "dwm", 3); XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &wmcheckwin, 1); /* EWMH support per view */ -- 2.15.1