xutil: check for text and len

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-31 08:55:15 +02:00
parent 3e325782de
commit e2de0270b2
1 changed files with 18 additions and 15 deletions

View File

@ -59,22 +59,25 @@ xutil_text_prop_get(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom,
return false; return false;
} }
/* Check whether the returned property value is just an ascii if(text && len)
* string or utf8 string. At the moment it doesn't handle
* COMPOUND_TEXT and multibyte but it's not needed... */
if(text && (prop_r->type == STRING || prop_r->type == UTF8_STRING))
{ {
void *prop_val = xcb_get_property_value(prop_r); /* Check whether the returned property value is just an ascii
*text = p_new(char, prop_r->value_len + 1); * string or utf8 string. At the moment it doesn't handle
/* use memcpy() because prop_val may not be \0 terminated */ * COMPOUND_TEXT and multibyte but it's not needed... */
memcpy(*text, prop_val, prop_r->value_len); if(prop_r->type == STRING || prop_r->type == UTF8_STRING)
(*text)[prop_r->value_len] = '\0'; {
*len = prop_r->value_len; void *prop_val = xcb_get_property_value(prop_r);
} *text = p_new(char, prop_r->value_len + 1);
else /* use memcpy() because prop_val may not be \0 terminated */
{ memcpy(*text, prop_val, prop_r->value_len);
*text = NULL; (*text)[prop_r->value_len] = '\0';
*len = 0; *len = prop_r->value_len;
}
else
{
*text = NULL;
*len = 0;
}
} }
p_delete(&prop_r); p_delete(&prop_r);