]> Skullheadx's Git Forge - dwm.git/commitdiff
getstate: fix access type and remove redundant cast
authorNRK <nrk@disroot.org>
Sun, 15 Feb 2026 22:59:13 +0000 (22:59 +0000)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 20 Feb 2026 14:31:28 +0000 (15:31 +0100)
WM_STATE is defined to be format == 32 which xlib returns as
`long` and so accessing it as `unsigned char` is incorrect.

and also &p is already an `unsigned char **` and so the cast was
completely redundant.

given the redundant cast, i assume `p` was `long *` at some time
but was changed to `unsigned char *` later, but the pointer
access (and the cast) wasn't updated.

also add a `format == 32` check as safety measure before
accessing, just in case.

dwm.c

diff --git a/dwm.c b/dwm.c
index fc4232eb5f0552a6dcdc7123924116be6f881f66..a5e1ce967d6b56c04dce4c8e5a5c9732d57bc9c5 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -897,10 +897,10 @@ getstate(Window w)
        Atom real;
 
        if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
-               &real, &format, &n, &extra, (unsigned char **)&p) != Success)
+               &real, &format, &n, &extra, &p) != Success)
                return -1;
-       if (n != 0)
-               result = *p;
+       if (n != 0 && format == 32)
+               result = *(long *)p;
        XFree(p);
        return result;
 }