r22188 - gnucash/trunk/src/backend/dbi - [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:48:42 EDT 2012


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

Modified:
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
Log:
[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().

[BP]


Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2012-05-21 15:43:52 UTC (rev 22187)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2012-05-21 15:48:41 UTC (rev 22188)
@@ -2008,16 +2008,26 @@
         {
             return NULL;
         }
-        else
-        {
-            time = dbi_result_get_datetime( dbi_row->result, col_name );
+	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 ) );
-        }
+                                                  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