From e0f54bc35683271d2ddd5d812243d7a5a42faad1 Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Sat, 29 Aug 2009 00:00:16 +0000 Subject: [PATCH] Fix bug where NULL dates on sqlite cause sigsegv git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18283 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/sql/gnc-backend-sql.c | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index e80102bd21..510287a5a7 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -1691,25 +1691,28 @@ load_date( const GncSqlBackend* be, GncSqlRow* row, if( G_VALUE_HOLDS_STRING( val ) ) { // Format of date is YYYYMMDD const gchar* s = g_value_get_string( val ); - gchar buf[5]; - GDateDay day; - guint month; - GDateYear year; - strncpy( buf, &s[0], 4 ); - buf[4] = '\0'; - year = (GDateYear)atoi( buf ); - strncpy( buf, &s[4], 2 ); - buf[2] = '\0'; - month = (guint)atoi( buf ); - strncpy( buf, &s[6], 2 ); - day = (GDateDay)atoi( buf ); + if( s != NULL ) { + gchar buf[5]; + GDateDay day; + guint month; + GDateYear year; - if( year != 0 || month != 0 || day != (GDateDay)0 ) { - date = g_date_new_dmy( day, month, year ); - (*setter)( pObject, date ); - g_date_free( date ); - } + strncpy( buf, &s[0], 4 ); + buf[4] = '\0'; + year = (GDateYear)atoi( buf ); + strncpy( buf, &s[4], 2 ); + buf[2] = '\0'; + month = (guint)atoi( buf ); + strncpy( buf, &s[6], 2 ); + day = (GDateDay)atoi( buf ); + + if( year != 0 || month != 0 || day != (GDateDay)0 ) { + date = g_date_new_dmy( day, month, year ); + (*setter)( pObject, date ); + g_date_free( date ); + } + } } else { PWARN( "Unknown date type: %s", G_VALUE_TYPE_NAME( val ) ); }