[hackers] [st][PATCH] x.c: modify xsettitle to work with musl libc

From: <joris.kbos_AT_gmail.com>
Date: Wed, 1 Jul 2020 21:29:25 +0200

From: Joris Klaasse Bos <joris.kbos_AT_gmail.com>

Before this commit, running st on a system with musl libc would
result in a segmentation fault. This is because musl implements
locales differently, which means the function
Xutf8TextListToTextProperty would fail, because the locale isn't
supported, leading to nonexistent memory being freed.

I've fixed this by checking if the locale is supported and using
XStringListToTextProperty otherwise.
---
 x.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/x.c b/x.c
index 210f184..a9632cb 100644
--- a/x.c
+++ b/x.c
_AT_@ -1585,8 +1585,11 @@ xsettitle(char *p)
 	XTextProperty prop;
 	DEFAULT(p, opt_title);
 
-	Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
-			&prop);
+	if (XSupportsLocale())
+		Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
+				&prop);
+	else
+		XStringListToTextProperty(&p, 1, &prop);
 	XSetWMName(xw.dpy, xw.win, &prop);
 	XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
 	XFree(prop.value);
-- 
2.27.0
Received on Wed Jul 01 2020 - 21:29:25 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 01 2020 - 21:36:34 CEST