From 4f4201976d71d51cd2579facbef203856e32297c Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 1 Nov 2018 11:12:20 +0000 Subject: [PATCH] Fix signedness of x properties Signed-off-by: Yuxuan Shui --- src/common.h | 24 ++++++++++++------------ src/compton.c | 2 +- src/types.h | 8 ++++---- src/win.c | 13 ++++--------- src/x.c | 6 +++--- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/common.h b/src/common.h index 6fb85d6..d853863 100644 --- a/src/common.h +++ b/src/common.h @@ -224,13 +224,13 @@ typedef struct { /// Structure representing Window property value. typedef struct winprop { - // All pointers have the same length, right? - // I wanted to use anonymous union but it's a GNU extension... union { - unsigned char *p8; - short *p16; - long *p32; - } data; + void *ptr; + uint8_t *p8; + int16_t *p16; + int32_t *p32; + uint32_t *c32; // 32bit cardinal + }; unsigned long nitems; Atom type; int format; @@ -1570,9 +1570,9 @@ winprop_get_int(winprop_t prop) { return 0; switch (prop.format) { - case 8: tgt = *(prop.data.p8); break; - case 16: tgt = *(prop.data.p16); break; - case 32: tgt = *(prop.data.p32); break; + case 8: tgt = *(prop.p8); break; + case 16: tgt = *(prop.p16); break; + case 32: tgt = *(prop.p32); break; default: assert(0); break; } @@ -1592,9 +1592,9 @@ wid_get_text_prop(session_t *ps, Window wid, Atom prop, static inline void free_winprop(winprop_t *pprop) { // Empty the whole structure to avoid possible issues - if (pprop->data.p8) { - cxfree(pprop->data.p8); - pprop->data.p8 = NULL; + if (pprop->ptr) { + cxfree(pprop->ptr); + pprop->ptr = NULL; } pprop->nitems = 0; } diff --git a/src/compton.c b/src/compton.c index c37d11c..e976431 100644 --- a/src/compton.c +++ b/src/compton.c @@ -912,7 +912,7 @@ get_root_tile(session_t *ps) { get_atom(ps, background_props_str[p]), 1L, XCB_ATOM_PIXMAP, 32); if (prop.nitems) { - pixmap = *prop.data.p32; + pixmap = *prop.p32; fill = false; free_winprop(&prop); break; diff --git a/src/types.h b/src/types.h index 1c6114f..f9bf14c 100644 --- a/src/types.h +++ b/src/types.h @@ -24,10 +24,10 @@ typedef struct { /// A structure representing margins around a rectangle. typedef struct { - int top; - int left; - int bottom; - int right; + unsigned int top; + unsigned int left; + unsigned int bottom; + unsigned int right; } margin_t; typedef uint32_t opacity_t; diff --git a/src/win.c b/src/win.c index c2d23d2..a1e3d09 100644 --- a/src/win.c +++ b/src/win.c @@ -251,7 +251,7 @@ wintype_t wid_get_prop_wintype(session_t *ps, Window wid) { for (unsigned i = 0; i < prop.nitems; ++i) { for (wintype_t j = 1; j < NUM_WINTYPES; ++j) { - if (ps->atoms_wintypes[j] == (Atom)prop.data.p32[i]) { + if (ps->atoms_wintypes[j] == (xcb_atom_t)prop.p32[i]) { free_winprop(&prop); return j; } @@ -271,12 +271,7 @@ bool wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def, winprop_t prop = wid_get_prop(ps, wid, ps->atom_opacity, 1L, XCB_ATOM_CARDINAL, 32); if (prop.nitems) { - // sanitize the opacity data, if opacity is out of bounds, - // assuming they are opaque - if (*prop.data.p32 < 0 || *prop.data.p32 > OPAQUE) - *out = OPAQUE; - else - *out = *prop.data.p32; + *out = *prop.c32; ret = true; } @@ -405,7 +400,7 @@ void win_update_prop_shadow_raw(session_t *ps, win *w) { if (!prop.nitems) { w->prop_shadow = -1; } else { - w->prop_shadow = *prop.data.p32; + w->prop_shadow = *prop.c32; } free_winprop(&prop); @@ -1236,7 +1231,7 @@ win_update_frame_extents(session_t *ps, win *w, Window client) { 4L, XCB_ATOM_CARDINAL, 32); if (prop.nitems == 4) { - const long * const extents = prop.data.p32; + const uint32_t * const extents = prop.c32; const bool changed = w->frame_extents.left != extents[0] || w->frame_extents.right != extents[1] || w->frame_extents.top != extents[2] || diff --git a/src/x.c b/src/x.c index 7e8aa3d..25dfedd 100644 --- a/src/x.c +++ b/src/x.c @@ -40,7 +40,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset, && (!rformat || format == rformat) && (8 == format || 16 == format || 32 == format)) { return (winprop_t) { - .data.p8 = data, + .ptr = data, .nitems = nitems, .type = type, .format = format, @@ -50,7 +50,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset, cxfree(data); return (winprop_t) { - .data.p8 = NULL, + .ptr = NULL, .nitems = 0, .type = AnyPropertyType, .format = 0 @@ -70,7 +70,7 @@ wid_get_prop_window(session_t *ps, Window wid, Atom aprop) { // Return it if (prop.nitems) { - p = *prop.data.p32; + p = *prop.p32; } free_winprop(&prop);