From 881ca572df59e2b39e4a123af68e46068b35a424 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 4 Mar 2016 19:41:32 +0100 Subject: [PATCH] Return NULL when empty property. --- source/x11-helper.c | 11 +++++++---- source/xrmoptions.c | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/x11-helper.c b/source/x11-helper.c index 699f611a..c0fc3b8b 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -89,11 +89,14 @@ char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom ) xcb_get_property_cookie_t c = xcb_get_property ( xcb->connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX ); xcb_get_property_reply_t *r = xcb_get_property_reply ( xcb->connection, c, NULL ); if ( r ) { - char *str = g_malloc ( xcb_get_property_value_length ( r ) + 1 ); - memcpy ( str, xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); - str[xcb_get_property_value_length ( r )] = '\0'; + if ( xcb_get_property_value_length ( r ) > 0 ) { + char *str = g_malloc ( xcb_get_property_value_length ( r ) + 1 ); + memcpy ( str, xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) ); + str[xcb_get_property_value_length ( r )] = '\0'; + free ( r ); + return str; + } free ( r ); - return str; } return NULL; } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 9d304a7e..3fb83fce 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -333,10 +333,12 @@ static void __config_parse_xresource_options_dynamic ( XrmDatabase xDB ) void config_parse_xresource_options_dynamic ( xcb_stuff *xcb ) { char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER ); - XrmDatabase xDB = XrmGetStringDatabase ( name ); - __config_parse_xresource_options_dynamic ( xDB ); - XrmDestroyDatabase ( xDB ); - g_free ( name ); + if ( name ) { + XrmDatabase xDB = XrmGetStringDatabase ( name ); + __config_parse_xresource_options_dynamic ( xDB ); + XrmDestroyDatabase ( xDB ); + g_free ( name ); + } } void config_parse_xresource_options_dynamic_file ( const char *filename ) {