add WINTYPE_UNKNOWN to prevent segfaults

This commit is contained in:
Christopher Jeffrey 2012-01-15 05:02:24 -06:00
parent 71d7352659
commit 51e2eec823
1 changed files with 10 additions and 13 deletions

View File

@ -32,6 +32,7 @@
#define CAN_DO_USABLE 0 #define CAN_DO_USABLE 0
typedef enum { typedef enum {
WINTYPE_UNKNOWN,
WINTYPE_DESKTOP, WINTYPE_DESKTOP,
WINTYPE_DOCK, WINTYPE_DOCK,
WINTYPE_TOOLBAR, WINTYPE_TOOLBAR,
@ -854,10 +855,7 @@ win_extents(Display *dpy, win *w) {
r.width = w->a.width + w->a.border_width * 2; r.width = w->a.width + w->a.border_width * 2;
r.height = w->a.height + w->a.border_width * 2; r.height = w->a.height + w->a.border_width * 2;
// check NUM_WINTYPES to prevent segfault if (win_type_shadow[w->window_type]) {
if (w->window_type >= 0
&& w->window_type < NUM_WINTYPES
&& win_type_shadow[w->window_type]) {
XRectangle sr; XRectangle sr;
w->shadow_dx = shadow_offset_x; w->shadow_dx = shadow_offset_x;
@ -1349,7 +1347,7 @@ get_wintype_prop(Display * dpy, Window w) {
unsigned long n, left, off; unsigned long n, left, off;
unsigned char *data; unsigned char *data;
ret = (wintype) - 1; ret = WINTYPE_UNKNOWN;
off = 0; off = 0;
do { do {
@ -1378,7 +1376,7 @@ get_wintype_prop(Display * dpy, Window w) {
} }
++off; ++off;
} while (left >= 4 && ret == (wintype) - 1); } while (left >= 4 && ret == WINTYPE_UNKNOWN);
return ret; return ret;
} }
@ -1391,19 +1389,19 @@ determine_wintype(Display *dpy, Window w, Window top) {
wintype type; wintype type;
type = get_wintype_prop(dpy, w); type = get_wintype_prop(dpy, w);
if (type != (wintype) - 1) return type; if (type != WINTYPE_UNKNOWN) return type;
set_ignore(dpy, NextRequest(dpy)); set_ignore(dpy, NextRequest(dpy));
if (!XQueryTree(dpy, w, &root_return, &parent_return, if (!XQueryTree(dpy, w, &root_return, &parent_return,
&children, &nchildren)) { &children, &nchildren)) {
/* XQueryTree failed. */ /* XQueryTree failed. */
if (children) XFree((void *)children); if (children) XFree((void *)children);
return (wintype) - 1; return WINTYPE_UNKNOWN;
} }
for (i = 0; i < nchildren; i++) { for (i = 0; i < nchildren; i++) {
type = determine_wintype(dpy, children[i], top); type = determine_wintype(dpy, children[i], top);
if (type != (wintype) - 1) return type; if (type != WINTYPE_UNKNOWN) return type;
} }
if (children) { if (children) {
@ -1411,7 +1409,7 @@ determine_wintype(Display *dpy, Window w, Window top) {
} }
if (w != top) { if (w != top) {
return (wintype) - 1; return WINTYPE_UNKNOWN;
} else { } else {
return WINTYPE_NORMAL; return WINTYPE_NORMAL;
} }
@ -1455,9 +1453,7 @@ map_win(Display *dpy, Window id,
#endif #endif
w->damaged = 0; w->damaged = 0;
if (fade && w->window_type >= 0 if (fade && win_type_fade[w->window_type]) {
&& w->window_type < NUM_WINTYPES
&& win_type_fade[w->window_type]) {
set_fade( set_fade(
dpy, w, 0, get_opacity_percent(dpy, w), dpy, w, 0, get_opacity_percent(dpy, w),
fade_in_step, 0, True, True); fade_in_step, 0, True, True);
@ -1712,6 +1708,7 @@ add_win(Display *dpy, Window id, Window prev, Bool override_redirect) {
new->opacity = OPAQUE; new->opacity = OPAQUE;
new->destroyed = False; new->destroyed = False;
new->need_configure = False; new->need_configure = False;
new->window_type = WINTYPE_UNKNOWN;
new->border_clip = None; new->border_clip = None;
new->prev_trans = 0; new->prev_trans = 0;