gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sun Jan 11 16:34:49 EST 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/7963421d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/609ca725 (commit)
	from  https://github.com/Gnucash/gnucash/commit/403fdd30 (commit)



commit 7963421dd228e5cb80fad325a7e3d3cfe7d76e61
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Jan 11 13:57:32 2015 -0800

    Bug 672760 - Postponed transaction applied invalid date
    
    Part 2: GDate can represent a wider range that GDateTime, so make
    sure that GDates outside of the range are clamped. The GDateTime
    range is 1 - 9999 CE, more than wide enough for most purposes. GDate
    can represent out to 65535CE, but the significant difference is that
    a freshly-cleared GDate is 0CE, which GDateTime won't accept. That we
    set to the Unix Epoch 0, 1970-Jan-1.

diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c
index a62c750..7044708 100644
--- a/src/libqof/qof/gnc-date.c
+++ b/src/libqof/qof/gnc-date.c
@@ -422,6 +422,7 @@ gnc_difftime (const time64 secs1, const time64 secs2)
 
 /****************************************************************************/
 
+
 GDateTime*
 gnc_g_date_time_new_from_timespec_local (Timespec ts)
 {
@@ -646,6 +647,22 @@ int gnc_date_get_last_mday (int month, int year)
     return last_day_of_month[0][month-1];
 }
 
+/* Safety function */
+static void
+gnc_gdate_range_check (GDate *gd)
+{
+    int year;
+    if (!g_date_valid (gd))
+    {
+	g_date_set_dmy (gd, 1, 1, 1970);
+	return;
+    }
+    year = g_date_get_year (gd);
+    // Adjust the GDate to fit in the range of GDateTime.
+    year = (year < 1 ? 1 : year > 9999 ? 9999 : year);
+    g_date_set_year (gd, year);
+    return;
+}
 /* Return the set dateFormat.
 
 return QofDateFormat: enumeration indicating preferred format
@@ -873,10 +890,14 @@ qof_print_date_buff (char * buff, size_t len, time64 t)
 size_t
 qof_print_gdate( char *buf, size_t len, const GDate *gd )
 {
+    GDate date;
+    g_date_clear (&date, 1);
+    date = *gd;
+    gnc_gdate_range_check (&date);
     return qof_print_date_dmy_buff( buf, len,
-                                    g_date_get_day(gd),
-                                    g_date_get_month(gd),
-                                    g_date_get_year(gd) );
+                                    g_date_get_day(&date),
+                                    g_date_get_month(&date),
+                                    g_date_get_year(&date) );
 }
 
 char *
@@ -1599,6 +1620,7 @@ GDate* gnc_g_date_new_today ()
 
 Timespec gdate_to_timespec (GDate d)
 {
+    gnc_gdate_range_check (&d);
     return gnc_dmy2timespec(g_date_get_day(&d),
                             g_date_get_month(&d),
                             g_date_get_year(&d));

commit 609ca72553c586f190c015552db7f25d60f928db
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Jan 11 10:27:09 2015 -0800

    Bug 672760 - Postponed transaction applied invalid date, causing segfault
    
    upon opening data file.
    Part 1: Prevent the crash by skipping instances with invalid dates.

diff --git a/src/gnome-utils/gnc-dense-cal.c b/src/gnome-utils/gnc-dense-cal.c
index f25e792..3b70255 100644
--- a/src/gnome-utils/gnc-dense-cal.c
+++ b/src/gnome-utils/gnc-dense-cal.c
@@ -1736,14 +1736,20 @@ gdc_add_tag_markings(GncDenseCal *cal, guint tag)
     {
         dates[idx] = g_date_new();
         gnc_dense_cal_model_get_instance(cal->model, tag, idx, dates[idx]);
-    }
 
-    if (g_date_get_julian(dates[0]) < g_date_get_julian(calDate))
+    }
+    if (g_date_valid(dates[0]))
     {
-        _gnc_dense_cal_set_month(cal, g_date_get_month(dates[0]), FALSE);
-        _gnc_dense_cal_set_year(cal, g_date_get_year(dates[0]), FALSE);
+	 if (g_date_get_julian(dates[0]) < g_date_get_julian(calDate))
+	 {
+	      _gnc_dense_cal_set_month(cal, g_date_get_month(dates[0]), FALSE);
+	      _gnc_dense_cal_set_year(cal, g_date_get_year(dates[0]), FALSE);
+	 }
+    }
+    else
+    {
+	 g_warning("Bad date, skipped.");
     }
-
     gdc_mark_add(cal, tag, name, info, num_marks, dates);
 
     for (idx = 0; idx < num_marks; idx++)



Summary of changes:
 src/gnome-utils/gnc-dense-cal.c | 16 +++++++++++-----
 src/libqof/qof/gnc-date.c       | 28 +++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list