Fix signedness of x properties

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-11-01 11:12:20 +00:00
parent 32e0b45255
commit 4f4201976d
5 changed files with 24 additions and 29 deletions

View File

@ -224,13 +224,13 @@ typedef struct {
/// Structure representing Window property value. /// Structure representing Window property value.
typedef struct winprop { typedef struct winprop {
// All pointers have the same length, right?
// I wanted to use anonymous union but it's a GNU extension...
union { union {
unsigned char *p8; void *ptr;
short *p16; uint8_t *p8;
long *p32; int16_t *p16;
} data; int32_t *p32;
uint32_t *c32; // 32bit cardinal
};
unsigned long nitems; unsigned long nitems;
Atom type; Atom type;
int format; int format;
@ -1570,9 +1570,9 @@ winprop_get_int(winprop_t prop) {
return 0; return 0;
switch (prop.format) { switch (prop.format) {
case 8: tgt = *(prop.data.p8); break; case 8: tgt = *(prop.p8); break;
case 16: tgt = *(prop.data.p16); break; case 16: tgt = *(prop.p16); break;
case 32: tgt = *(prop.data.p32); break; case 32: tgt = *(prop.p32); break;
default: assert(0); default: assert(0);
break; break;
} }
@ -1592,9 +1592,9 @@ wid_get_text_prop(session_t *ps, Window wid, Atom prop,
static inline void static inline void
free_winprop(winprop_t *pprop) { free_winprop(winprop_t *pprop) {
// Empty the whole structure to avoid possible issues // Empty the whole structure to avoid possible issues
if (pprop->data.p8) { if (pprop->ptr) {
cxfree(pprop->data.p8); cxfree(pprop->ptr);
pprop->data.p8 = NULL; pprop->ptr = NULL;
} }
pprop->nitems = 0; pprop->nitems = 0;
} }

View File

@ -912,7 +912,7 @@ get_root_tile(session_t *ps) {
get_atom(ps, background_props_str[p]), get_atom(ps, background_props_str[p]),
1L, XCB_ATOM_PIXMAP, 32); 1L, XCB_ATOM_PIXMAP, 32);
if (prop.nitems) { if (prop.nitems) {
pixmap = *prop.data.p32; pixmap = *prop.p32;
fill = false; fill = false;
free_winprop(&prop); free_winprop(&prop);
break; break;

View File

@ -24,10 +24,10 @@ typedef struct {
/// A structure representing margins around a rectangle. /// A structure representing margins around a rectangle.
typedef struct { typedef struct {
int top; unsigned int top;
int left; unsigned int left;
int bottom; unsigned int bottom;
int right; unsigned int right;
} margin_t; } margin_t;
typedef uint32_t opacity_t; typedef uint32_t opacity_t;

View File

@ -251,7 +251,7 @@ wintype_t wid_get_prop_wintype(session_t *ps, Window wid) {
for (unsigned i = 0; i < prop.nitems; ++i) { for (unsigned i = 0; i < prop.nitems; ++i) {
for (wintype_t j = 1; j < NUM_WINTYPES; ++j) { 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); free_winprop(&prop);
return j; 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); winprop_t prop = wid_get_prop(ps, wid, ps->atom_opacity, 1L, XCB_ATOM_CARDINAL, 32);
if (prop.nitems) { if (prop.nitems) {
// sanitize the opacity data, if opacity is out of bounds, *out = *prop.c32;
// assuming they are opaque
if (*prop.data.p32 < 0 || *prop.data.p32 > OPAQUE)
*out = OPAQUE;
else
*out = *prop.data.p32;
ret = true; ret = true;
} }
@ -405,7 +400,7 @@ void win_update_prop_shadow_raw(session_t *ps, win *w) {
if (!prop.nitems) { if (!prop.nitems) {
w->prop_shadow = -1; w->prop_shadow = -1;
} else { } else {
w->prop_shadow = *prop.data.p32; w->prop_shadow = *prop.c32;
} }
free_winprop(&prop); free_winprop(&prop);
@ -1236,7 +1231,7 @@ win_update_frame_extents(session_t *ps, win *w, Window client) {
4L, XCB_ATOM_CARDINAL, 32); 4L, XCB_ATOM_CARDINAL, 32);
if (prop.nitems == 4) { 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] || const bool changed = w->frame_extents.left != extents[0] ||
w->frame_extents.right != extents[1] || w->frame_extents.right != extents[1] ||
w->frame_extents.top != extents[2] || w->frame_extents.top != extents[2] ||

View File

@ -40,7 +40,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
&& (!rformat || format == rformat) && (!rformat || format == rformat)
&& (8 == format || 16 == format || 32 == format)) { && (8 == format || 16 == format || 32 == format)) {
return (winprop_t) { return (winprop_t) {
.data.p8 = data, .ptr = data,
.nitems = nitems, .nitems = nitems,
.type = type, .type = type,
.format = format, .format = format,
@ -50,7 +50,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
cxfree(data); cxfree(data);
return (winprop_t) { return (winprop_t) {
.data.p8 = NULL, .ptr = NULL,
.nitems = 0, .nitems = 0,
.type = AnyPropertyType, .type = AnyPropertyType,
.format = 0 .format = 0
@ -70,7 +70,7 @@ wid_get_prop_window(session_t *ps, Window wid, Atom aprop) {
// Return it // Return it
if (prop.nitems) { if (prop.nitems) {
p = *prop.data.p32; p = *prop.p32;
} }
free_winprop(&prop); free_winprop(&prop);