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;
}
/* Check whether the returned property value is just an ascii
* 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))
if(text && len)
{
void *prop_val = xcb_get_property_value(prop_r);
*text = p_new(char, prop_r->value_len + 1);
/* use memcpy() because prop_val may not be \0 terminated */
memcpy(*text, prop_val, prop_r->value_len);
(*text)[prop_r->value_len] = '\0';
*len = prop_r->value_len;
}
else
{
*text = NULL;
*len = 0;
/* Check whether the returned property value is just an ascii
* string or utf8 string. At the moment it doesn't handle
* COMPOUND_TEXT and multibyte but it's not needed... */
if(prop_r->type == STRING || prop_r->type == UTF8_STRING)
{
void *prop_val = xcb_get_property_value(prop_r);
*text = p_new(char, prop_r->value_len + 1);
/* use memcpy() because prop_val may not be \0 terminated */
memcpy(*text, prop_val, prop_r->value_len);
(*text)[prop_r->value_len] = '\0';
*len = prop_r->value_len;
}
else
{
*text = NULL;
*len = 0;
}
}
p_delete(&prop_r);