From da6980afc2b04aa752f0904e900070ccb8cdd4d4 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Mon, 7 May 2012 22:54:56 +0000 Subject: [PATCH] [Bug 674862] Gnucash crashes after creating a new SX using the Mortgage Wizard and SQL Backend This addresses the crash reported on Ubuntu with Postgres by Krzysiek. The stack trace he posted showed the crash was the result of dereferencing a NULL GDate*, and this change protects against that. It still doesn't address the more basic problem of why on Win32 and with mysql and pgsql (but not SQLite3) the mortgage wizard is writing corrupt dates. [BP] git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22171 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/SchedXaction.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c index 8db9d41d81..d667044133 100644 --- a/src/engine/SchedXaction.c +++ b/src/engine/SchedXaction.c @@ -577,12 +577,23 @@ xaccSchedXactionSetName( SchedXaction *sx, const gchar *newName ) const GDate* xaccSchedXactionGetStartDate(const SchedXaction *sx ) { + g_assert (sx); return &sx->start_date; } void xaccSchedXactionSetStartDate( SchedXaction *sx, const GDate* newStart ) { + if ( newStart == NULL || !g_date_valid( newStart )) + { + /* XXX: I reject the bad data - is this the right + * thing to do . + * This warning is only human readable - the caller + * doesn't know the call failed. This is bad + */ + g_critical("Invalid Start Date"); + return; + } gnc_sx_begin_edit(sx); sx->start_date = *newStart; qof_instance_set_dirty(&sx->inst); @@ -592,27 +603,29 @@ xaccSchedXactionSetStartDate( SchedXaction *sx, const GDate* newStart ) gboolean xaccSchedXactionHasEndDate( const SchedXaction *sx ) { - return g_date_valid( &sx->end_date ); + return sx != NULL && g_date_valid( &sx->end_date ); } const GDate* xaccSchedXactionGetEndDate(const SchedXaction *sx ) { + g_assert (sx); return &sx->end_date; } void xaccSchedXactionSetEndDate( SchedXaction *sx, const GDate *newEnd ) { - if ( g_date_valid( newEnd ) - && g_date_compare( newEnd, &sx->start_date ) < 0 ) + if (newEnd == NULL + || !g_date_valid( newEnd ) + || g_date_compare( newEnd, &sx->start_date ) < 0 ) { /* XXX: I reject the bad data - is this the right * thing to do . * This warning is only human readable - the caller * doesn't know the call failed. This is bad */ - g_critical("New end date before start date"); + g_critical("Bad End Date: Invalid or before Start Date"); return; }