r22189 - gnucash/branches/2.4/src/backend/dbi - [r22188][Bug #674862] Gnucash crashes after creating a new SX using the Mortgage Wizard and SQL Backend

John Ralls jralls at code.gnucash.org
Mon May 21 11:50:35 EDT 2012


Author: jralls
Date: 2012-05-21 11:50:35 -0400 (Mon, 21 May 2012)
New Revision: 22189
Trac: http://svn.gnucash.org/trac/changeset/22189

Modified:
   gnucash/branches/2.4/src/backend/dbi/gnc-backend-dbi.c
Log:
[r22188][Bug #674862] Gnucash crashes after creating a new SX using the Mortgage Wizard and SQL Backend 


Special-cases dbi_result_get_datetime returning -1 to work around a bug in MinGW's implementation of gmtime().


Modified: gnucash/branches/2.4/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/branches/2.4/src/backend/dbi/gnc-backend-dbi.c	2012-05-21 15:48:41 UTC (rev 22188)
+++ gnucash/branches/2.4/src/backend/dbi/gnc-backend-dbi.c	2012-05-21 15:50:35 UTC (rev 22189)
@@ -2005,16 +2005,26 @@
         {
             return NULL;
         }
-        else
-        {
-            time = dbi_result_get_datetime( dbi_row->result, col_name );
-            (void)gmtime_r( &time, &tm_struct );
-            (void)g_value_init( value, G_TYPE_STRING );
-            g_value_take_string( value,
-                                 g_strdup_printf( "%d%02d%02d%02d%02d%02d",
-                                                  1900 + tm_struct.tm_year, tm_struct.tm_mon + 1, tm_struct.tm_mday,
-                                                  tm_struct.tm_hour, tm_struct.tm_min, tm_struct.tm_sec ) );
-        }
+	time = dbi_result_get_datetime( dbi_row->result, col_name );
+	/* Protect gmtime from time values < 0 to work around a mingw
+	   bug that fills struct_tm with garbage values which in turn
+	   creates a string that GDate can't parse. */
+	if (time >= 0)
+	  {
+	    (void)gmtime_r( &time, &tm_struct );
+	    (void)g_value_init( value, G_TYPE_STRING );
+	    g_value_take_string( value,
+				 g_strdup_printf( "%d%02d%02d%02d%02d%02d",
+						  1900 + tm_struct.tm_year,
+						  tm_struct.tm_mon + 1,
+						  tm_struct.tm_mday,
+						  tm_struct.tm_hour,
+						  tm_struct.tm_min,
+						  tm_struct.tm_sec ) );
+	  }
+	else
+	  g_value_take_string (value, "19691231235959");
+        
         break;
     default:
         PERR( "Field %s: unknown DBI_TYPE: %d\n", col_name, type );



More information about the gnucash-changes mailing list