From 65bdc67ac6f9743c2de265122dc5511218e79466 Mon Sep 17 00:00:00 2001 From: Pierre Wieser Date: Sun, 16 Jan 2011 01:05:51 +0100 Subject: [PATCH] Fix NABoxed when the structure has not been allocated --- ChangeLog | 7 +++++++ src/core/na-boxed.c | 41 +++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32c9fb01..b21c2f1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,13 @@ 2011-01-15 Pierre Wieser + * src/core/na-boxed.c + (na_boxed_free): Only free a non null structure. + (na_boxed_new_from_string_with_sep): Do not try to split an empty string. + (na_boxed_get_boolean, na_boxed_get_pointer, na_boxed_get_string, + na_boxed_get_string_list, na_boxed_get_uint, na_boxed_get_uint_list): + Do not try to return a value for a null structure. + * m4/na-maintainer-mode.m4: Define a conditional when in maintainer mode. 2011-01-14 Pierre Wieser diff --git a/src/core/na-boxed.c b/src/core/na-boxed.c index a20b58b5..f0006a4e 100644 --- a/src/core/na-boxed.c +++ b/src/core/na-boxed.c @@ -339,15 +339,17 @@ na_boxed_free( NABoxed *boxed ) static const gchar *thisfn = "na_boxed_free"; const BoxedDef *def; - def = get_boxed_def( boxed->type ); - if( def ){ - if( def->free ){ - ( *def->free )( boxed ); - g_debug( "na_boxed_free: boxed=%p", ( void * ) boxed ); - g_free( boxed ); - } else { - g_warning( "%s: unable to free the content: '%s' type does not provide 'free' function", - thisfn, def->label ); + if( boxed ){ + def = get_boxed_def( boxed->type ); + if( def ){ + if( def->free ){ + ( *def->free )( boxed ); + g_debug( "na_boxed_free: boxed=%p", ( void * ) boxed ); + g_free( boxed ); + } else { + g_warning( "%s: unable to free the content: '%s' type does not provide 'free' function", + thisfn, def->label ); + } } } } @@ -413,14 +415,17 @@ na_boxed_new_from_string_with_sep( guint type, const gchar *string, const gchar gchar **array; boxed = NULL; + def = get_boxed_def( type ); if( def ){ if( def->from_array ){ boxed = boxed_new(); boxed->type = type; - array = string ? g_strsplit( string, sep, -1 ) : NULL; - ( *def->from_array )( boxed, ( const gchar ** ) array ); - g_strfreev( array ); + if( string && strlen( string )){ + array = string ? g_strsplit( string, sep, -1 ) : NULL; + ( *def->from_array )( boxed, ( const gchar ** ) array ); + g_strfreev( array ); + } } else { g_warning( "%s: unable to initialize the content: '%s' type does not provide 'from_array' function", thisfn, def->label ); @@ -447,7 +452,7 @@ na_boxed_get_boolean( const NABoxed *boxed ) gboolean value; value = FALSE; - if( boxed->type == NA_BOXED_TYPE_BOOLEAN && boxed->is_set ){ + if( boxed && boxed->type == NA_BOXED_TYPE_BOOLEAN && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_bool ){ @@ -478,7 +483,7 @@ na_boxed_get_pointer( const NABoxed *boxed ) gpointer value; value = NULL; - if( boxed->is_set ){ + if( boxed && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_pointer ){ @@ -510,7 +515,7 @@ na_boxed_get_string( const NABoxed *boxed ) gchar *value; value = NULL; - if( boxed->type == NA_BOXED_TYPE_STRING && boxed->is_set ){ + if( boxed && boxed->type == NA_BOXED_TYPE_STRING && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_string ){ @@ -542,7 +547,7 @@ na_boxed_get_string_list( const NABoxed *boxed ) GSList *value; value = NULL; - if( boxed->type == NA_BOXED_TYPE_STRING_LIST && boxed->is_set ){ + if( boxed && boxed->type == NA_BOXED_TYPE_STRING_LIST && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_string_list ){ @@ -573,7 +578,7 @@ na_boxed_get_uint( const NABoxed *boxed ) guint value; value = 0; - if( boxed->type == NA_BOXED_TYPE_UINT && boxed->is_set ){ + if( boxed && boxed->type == NA_BOXED_TYPE_UINT && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_uint ){ @@ -605,7 +610,7 @@ na_boxed_get_uint_list( const NABoxed *boxed ) GList *value; value = NULL; - if( boxed->type == NA_BOXED_TYPE_UINT_LIST && boxed->is_set ){ + if( boxed && boxed->type == NA_BOXED_TYPE_UINT_LIST && boxed->is_set ){ def = get_boxed_def( boxed->type ); if( def ){ if( def->get_uint_list ){ -- 2.11.4.GIT