Fix loading saved states on 64-bit systems
authorBrad Jorsch <anomie@users.sourceforge.net>
Fri, 9 Apr 2010 19:49:06 +0000 (9 15:49 -0400)
committerCarlos R. Mafra <crmafra@gmail.com>
Mon, 12 Apr 2010 07:58:37 +0000 (12 09:58 +0200)
One misuse of CARD32 was missed back when someone fixed the 64-bit
issues (background: X has 8-bit, 16-bit, and "32-bit stored in a long"
data formats; on a 64-bit system, long is 64 bits). This was causing
minimized windows to be restored as shaded, and possibly occasional
crashes, when wmaker was restarted.

Also, throw in a safety check that 10 items really were returned before
trying to access them.

src/window.c

index 8518739..8863275 100644 (file)
@@ -2338,12 +2338,12 @@ static int getSavedState(Window window, WSavedState ** state)
        int fmt_ret;
        unsigned long nitems_ret;
        unsigned long bytes_after_ret;
-       CARD32 *data;
+       long *data;
 
        if (XGetWindowProperty(dpy, window, _XA_WINDOWMAKER_STATE, 0, 10,
                               True, _XA_WINDOWMAKER_STATE,
                               &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
-                              (unsigned char **)&data) != Success || !data)
+                              (unsigned char **)&data) != Success || !data || nitems_ret < 10)
                return 0;
 
        *state = wmalloc(sizeof(WSavedState));