r18283 - gnucash/trunk/src/backend/sql - Fix bug where NULL dates on sqlite cause sigsegv

Phil Longstaff plongstaff at code.gnucash.org
Fri Aug 28 20:00:16 EDT 2009


Author: plongstaff
Date: 2009-08-28 20:00:16 -0400 (Fri, 28 Aug 2009)
New Revision: 18283
Trac: http://svn.gnucash.org/trac/changeset/18283

Modified:
   gnucash/trunk/src/backend/sql/gnc-backend-sql.c
Log:
Fix bug where NULL dates on sqlite cause sigsegv


Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2009-08-28 23:59:47 UTC (rev 18282)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2009-08-29 00:00:16 UTC (rev 18283)
@@ -1691,25 +1691,28 @@
 		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 ) );
         }



More information about the gnucash-changes mailing list