diff --git a/common/base-typemaps.i b/common/base-typemaps.i index 62c8f96f61..e9f7ac0ec8 100644 --- a/common/base-typemaps.i +++ b/common/base-typemaps.i @@ -21,6 +21,7 @@ * Boston, MA 02110-1301, USA gnu@gnu.org * * * \********************************************************************/ +%include "constraints.i" typedef void * gpointer; // Not sure why SWIG doesn't figure this out. %typemap(newfree) gchar * "g_free($1);" @@ -93,22 +94,25 @@ typedef char gchar; %typemap(out) struct tm * { SCM tm = scm_c_make_vector(11, SCM_UNDEFINED); struct tm* t = $1; - SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec)); - SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min)); - SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour)); - SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday)); - SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon)); - SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year)); - SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday)); - SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday)); - SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst)); + if (t != NULL) + { + SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec)); + SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min)); + SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour)); + SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday)); + SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon)); + SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year)); + SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday)); + SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday)); + SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst)); %#ifdef HAVE_STRUCT_TM_GMTOFF - SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff)); - SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset")); + SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff)); + SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset")); %#else - SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0)); - SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT")); + SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0)); + SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT")); %#endif + } $result = tm; } @@ -117,22 +121,25 @@ typedef char gchar; %typemap(argout) struct tm * { struct tm* t = $1; SCM tm = $input; - SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec)); - SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min)); - SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour)); - SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday)); - SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon)); - SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year)); - SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday)); - SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday)); - SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst)); + if (t == NULL) + { + SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec)); + SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min)); + SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour)); + SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday)); + SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon)); + SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year)); + SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday)); + SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday)); + SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst)); %#ifdef HAVE_STRUCT_TM_GMTOFF - SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff)); - SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset")); + SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff)); + SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset")); %#else - SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0)); - SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT")); + SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0)); + SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT")); %#endif + } } %define GLIST_HELPER_INOUT(ListType, ElemSwigType) diff --git a/gnucash/gnome-utils/gnc-cell-renderer-date.c b/gnucash/gnome-utils/gnc-cell-renderer-date.c index 210c04ad70..e47a386511 100644 --- a/gnucash/gnome-utils/gnc-cell-renderer-date.c +++ b/gnucash/gnome-utils/gnc-cell-renderer-date.c @@ -437,7 +437,8 @@ gcrd_time2dmy (time64 raw_time, gint *day, gint *month, gint *year) struct tm * timeinfo; timeinfo = gnc_localtime (&raw_time); - + if (timeinfo == NULL) + return FALSE; *day = timeinfo->tm_mday; *month = timeinfo->tm_mon + 1; *year = timeinfo->tm_year + 1900; diff --git a/gnucash/gnome/assistant-loan.c b/gnucash/gnome/assistant-loan.c index 9ed325755e..26370f5c38 100644 --- a/gnucash/gnome/assistant-loan.c +++ b/gnucash/gnome/assistant-loan.c @@ -1091,11 +1091,14 @@ loan_info_page_save( GtkAssistant *assistant, gpointer user_data ) tmpTT = gnc_date_edit_get_date( ldd->prmStartDateGDE ); tmpTm = gnc_localtime ( &tmpTT ); - g_date_set_dmy( ldd->ld.startDate, - tmpTm->tm_mday, - (tmpTm->tm_mon + 1), - (1900 + tmpTm->tm_year) ); - gnc_tm_free (tmpTm); + if (tmpTm) + { + g_date_set_dmy( ldd->ld.startDate, + tmpTm->tm_mday, + (tmpTm->tm_mon + 1), + (1900 + tmpTm->tm_year) ); + gnc_tm_free (tmpTm); + } } /* len / periods */ diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c index 5fc7c7eeb1..17e019e8cf 100644 --- a/libgnucash/engine/Transaction.c +++ b/libgnucash/engine/Transaction.c @@ -2426,10 +2426,13 @@ xaccTransGetDatePostedGDate (const Transaction *trans) */ time64 time = xaccTransGetDate(trans); struct tm *stm = gnc_gmtime(&time); - g_date_set_dmy(&result, stm->tm_mday, - (GDateMonth)(stm->tm_mon + 1), - stm->tm_year + 1900); - free(stm); + if (stm) + { + g_date_set_dmy(&result, stm->tm_mday, + (GDateMonth)(stm->tm_mon + 1), + stm->tm_year + 1900); + free(stm); + } } } return result;