From ad1ba561053d7d73cd983184e70956c8bc2df8a0 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 10 Dec 2016 15:08:03 -0800 Subject: [PATCH] Bug 772484 - Segfault on Transaction edit Fix a couple of places where we can pass a NULL GDateTime* if the database contains a bad date. --- src/libqof/qof/gnc-date.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c index 27c52ff77c..527671dbdf 100644 --- a/src/libqof/qof/gnc-date.c +++ b/src/libqof/qof/gnc-date.c @@ -431,7 +431,9 @@ gnc_g_date_time_new_from_timespec_local (Timespec ts) { GDateTime *gdt1 = gnc_g_date_time_new_from_unix_local (ts.tv_sec); double nsecs = ((double)ts.tv_nsec + 0.5)/ 1000000000.0L; - GDateTime *gdt2 = g_date_time_add_seconds (gdt1, nsecs); + GDateTime *gdt2 = NULL; + g_return_val_if_fail (gdt1 != NULL, NULL); + gdt2 = g_date_time_add_seconds (gdt1, nsecs); g_date_time_unref (gdt1); g_assert (g_date_time_to_unix (gdt2) == ts.tv_sec + (nsecs >= 1.0 ? (gint64)nsecs : 0)); return gdt2; @@ -1486,8 +1488,11 @@ gnc_iso8601_to_timespec_gmt(const char *str) gdt = g_date_time_new_utc (year, month, day, hour, minute, second); } - time.tv_sec = g_date_time_to_unix (gdt); - time.tv_nsec = g_date_time_get_microsecond (gdt) * 1000; + if (gdt != NULL) + { + time.tv_sec = g_date_time_to_unix (gdt); + time.tv_nsec = g_date_time_get_microsecond (gdt) * 1000; + } g_date_time_unref (gdt); return time; }