diff --git a/icccm/icccm.c b/icccm/icccm.c index cf22a25..eb8f850 100644 --- a/icccm/icccm.c +++ b/icccm/icccm.c @@ -524,6 +524,7 @@ xcb_get_wm_size_hints (xcb_connection_t *c, { xcb_get_property_cookie_t cookie; xcb_get_property_reply_t *rep; + long length; cookie = xcb_get_property (c, 0, window, property, WM_SIZE_HINTS, @@ -532,28 +533,21 @@ xcb_get_wm_size_hints (xcb_connection_t *c, if (!rep) return 0; + length = xcb_get_property_value_length (rep); if ((rep->type == WM_SIZE_HINTS) && ((rep->format == 8) || (rep->format == 16) || (rep->format == 32)) && - (rep->value_len >= 15)) /* OldNumPropSizeElements = 15 (pre-ICCCM) */ + (length >= 15)) /* OldNumPropSizeElements = 15 (pre-ICCCM) */ { - char *prop; - long length; - - length = xcb_get_property_value_length (rep); - /* FIXME: in GetProp.c of xcl, one move the memory. - * Should we do that too ? */ - prop = (char *)malloc(sizeof(char)*length); - memcpy(prop, xcb_get_property_value (rep), length); - prop[length] = '\0'; - hints = (xcb_size_hints_t *)strdup (prop); + memcpy (hints, (xcb_size_hints_t *) xcb_get_property_value (rep), + length * rep->format >> 3); *supplied = (USPosition | USSize | PPosition | PSize | PMinSize | PMaxSize | PResizeInc | PAspect); - if (rep->value_len >= 18) /* NumPropSizeElements = 18 (ICCCM version 1) */ + if (length >= 18) /* NumPropSizeElements = 18 (ICCCM version 1) */ *supplied |= (PBaseSize | PWinGravity); else { @@ -568,7 +562,6 @@ xcb_get_wm_size_hints (xcb_connection_t *c, return 1; } - hints = NULL; free (rep); return 0; @@ -826,7 +819,6 @@ xcb_get_wm_hints (xcb_connection_t *c, xcb_get_property_cookie_t cookie; xcb_get_property_reply_t *rep; xcb_wm_hints_t *hints; - char *prop; long length; cookie = xcb_get_property (c, 0, window, @@ -836,8 +828,9 @@ xcb_get_wm_hints (xcb_connection_t *c, if (!rep) return NULL; + length = xcb_get_property_value_length (rep); if ((rep->type != WM_HINTS) || - (rep->value_len < (XCB_NUM_WM_HINTS_ELEMENTS - 1)) || + (length < (XCB_NUM_WM_HINTS_ELEMENTS - 1)) || (rep->format != 32)) { free (rep); @@ -850,11 +843,9 @@ xcb_get_wm_hints (xcb_connection_t *c, return NULL; } - length = xcb_get_property_value_length (rep); - prop = (char *) xcb_get_property_value (rep); - prop[length] = '\0'; - hints = (xcb_wm_hints_t *)strdup (prop); - if (rep->value_len < XCB_NUM_WM_HINTS_ELEMENTS) + memcpy(hints, (xcb_size_hints_t *) xcb_get_property_value (rep), + length * rep->format >> 3); + if (length < XCB_NUM_WM_HINTS_ELEMENTS) hints->window_group = XCB_NONE; return hints;