x: wid_get_text_prop shouldn't return 0 strings

Downstream code expect wid_get_text_prop to return at least 1 string.
However wid_get_text_prop would return 0 strings when the property is
set to an empty string.

Fixes: dc37370a66

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-10-23 15:14:17 +01:00
parent 6c6b1afeb3
commit 3576a92da3
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 16 additions and 2 deletions

View File

@ -543,10 +543,13 @@ int win_update_name(session_t *ps, struct managed_win *w) {
}
if (!(wid_get_text_prop(ps, w->client_win, ps->atoms->a_NET_WM_NAME, &strlst, &nstr))) {
log_trace("(%#010x): _NET_WM_NAME unset, falling back to WM_NAME.",
log_debug("(%#010x): _NET_WM_NAME unset, falling back to WM_NAME.",
w->client_win);
if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_NAME, &strlst, &nstr)) {
log_debug("Unsetting window name for %#010x", w->client_win);
free(w->name);
w->name = NULL;
return -1;
}
}
@ -560,7 +563,7 @@ int win_update_name(session_t *ps, struct managed_win *w) {
free(strlst);
log_trace("(%#010x): client = %#010x, name = \"%s\", "
log_debug("(%#010x): client = %#010x, name = \"%s\", "
"ret = %d",
w->base.id, w->client_win, w->name, ret);
return ret;

11
src/x.c
View File

@ -145,6 +145,17 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char **
nstr += 1;
}
if (nstr == 0) {
// The property is set to an empty string, in that case, we return one
// string
char **strlst = malloc(sizeof(char *));
strlst[0] = "";
*pnstr = 1;
*pstrlst = strlst;
free(r);
return true;
}
// Allocate the pointers and the strings together
void *buf = NULL;
if (posix_memalign(&buf, alignof(char *), length + sizeof(char *) * nstr + 1) != 0) {