r22755 - gnucash/trunk/src/register/register-gnome - Avoid a crash when entering invalid dates (e.g., enter "111" for a transaction date).

Mike Alexander mta at code.gnucash.org
Tue Feb 5 23:24:38 EST 2013


Author: mta
Date: 2013-02-05 23:24:38 -0500 (Tue, 05 Feb 2013)
New Revision: 22755
Trac: http://svn.gnucash.org/trac/changeset/22755

Modified:
   gnucash/trunk/src/register/register-gnome/datecell-gnome.c
Log:
Avoid a crash when entering invalid dates (e.g., enter "111" for a transaction date).
gnc_parse_date is ignoring the return code from qof_scan_date which causes it to
send uninitialized values to gnc_mktime which crashes if the date is too ridiculous.
Presumably this worked before because mktime took anything without crashing.

Modified: gnucash/trunk/src/register/register-gnome/datecell-gnome.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/datecell-gnome.c	2013-02-05 01:45:49 UTC (rev 22754)
+++ gnucash/trunk/src/register/register-gnome/datecell-gnome.c	2013-02-06 04:24:38 UTC (rev 22755)
@@ -100,7 +100,15 @@
     if (!parsed) return;
     if (!datestr) return;
 
-    qof_scan_date (datestr, &day, &month, &year);
+    if (!qof_scan_date (datestr, &day, &month, &year))
+    {
+        // Couldn't parse date, use today
+        struct tm tm_today;
+        gnc_tm_get_today_start (&tm_today);
+        day = tm_today.tm_mday;
+        month = tm_today.tm_mon + 1;
+        year = tm_today.tm_year + 1900;
+    }
 
     // If we have an auto-read-only threshold, do not accept a date that is
     // older than the threshold.



More information about the gnucash-changes mailing list