Avoid passing invalid arguments to functions to get rid of some non-fatal asserts.

This commit is contained in:
Mike Alexander 2015-08-06 17:43:57 -04:00
parent 7e95ac28a7
commit 655c04bd68
3 changed files with 32 additions and 17 deletions

View File

@ -714,7 +714,8 @@ _find_unreferenced_vars(gchar *key,
gpointer value, gpointer value,
HashListPair *cb_pair) HashListPair *cb_pair)
{ {
if (!g_hash_table_lookup_extended(cb_pair->hash, key, NULL, NULL)) if (cb_pair->hash == NULL ||
!g_hash_table_lookup_extended(cb_pair->hash, key, NULL, NULL))
{ {
g_debug("variable [%s] not found", key); g_debug("variable [%s] not found", key);
cb_pair->list = g_list_append(cb_pair->list, key); cb_pair->list = g_list_append(cb_pair->list, key);
@ -788,20 +789,27 @@ gnc_sx_instance_model_update_sx_instances(GncSxInstanceModel *model, SchedXactio
// handle variables // handle variables
{ {
HashListPair removed_cb_data, added_cb_data;
GList *removed_var_names = NULL, *added_var_names = NULL; GList *removed_var_names = NULL, *added_var_names = NULL;
GList *inst_iter = NULL; GList *inst_iter = NULL;
if (existing->variable_names != NULL)
{
HashListPair removed_cb_data;
removed_cb_data.hash = new_instances->variable_names; removed_cb_data.hash = new_instances->variable_names;
removed_cb_data.list = NULL; removed_cb_data.list = NULL;
g_hash_table_foreach(existing->variable_names, (GHFunc)_find_unreferenced_vars, &removed_cb_data); g_hash_table_foreach(existing->variable_names, (GHFunc)_find_unreferenced_vars, &removed_cb_data);
removed_var_names = removed_cb_data.list; removed_var_names = removed_cb_data.list;
}
g_debug("%d removed variables", g_list_length(removed_var_names)); g_debug("%d removed variables", g_list_length(removed_var_names));
if (new_instances->variable_names != NULL)
{
HashListPair added_cb_data;
added_cb_data.hash = existing->variable_names; added_cb_data.hash = existing->variable_names;
added_cb_data.list = NULL; added_cb_data.list = NULL;
g_hash_table_foreach(new_instances->variable_names, (GHFunc)_find_unreferenced_vars, &added_cb_data); g_hash_table_foreach(new_instances->variable_names, (GHFunc)_find_unreferenced_vars, &added_cb_data);
added_var_names = added_cb_data.list; added_var_names = added_cb_data.list;
}
g_debug("%d added variables", g_list_length(added_var_names)); g_debug("%d added variables", g_list_length(added_var_names));
if (existing->variable_names != NULL) if (existing->variable_names != NULL)

View File

@ -638,7 +638,8 @@ xaccSchedXactionSetEndDate( SchedXaction *sx, const GDate *newEnd )
* the SX is to run "forever". See gnc_sxed_save_sx() and * the SX is to run "forever". See gnc_sxed_save_sx() and
* schedXact_editor_populate() in dialog-sx-editor.c. * schedXact_editor_populate() in dialog-sx-editor.c.
*/ */
if (newEnd == NULL || 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 /* XXX: I reject the bad data - is this the right
* thing to do <rgmerk>. * thing to do <rgmerk>.

View File

@ -2093,9 +2093,12 @@ gnc_template_register_get_fdebt_entry (VirtualLocation virt_loc,
Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc); Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc);
char *formula = NULL; char *formula = NULL;
if (split)
{
qof_instance_get (QOF_INSTANCE (split), qof_instance_get (QOF_INSTANCE (split),
"sx-debit-formula", &formula, "sx-debit-formula", &formula,
NULL); NULL);
}
return formula; return formula;
} }
@ -2124,9 +2127,12 @@ gnc_template_register_get_fcred_entry (VirtualLocation virt_loc,
Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc); Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc);
char *formula = NULL; char *formula = NULL;
if (split)
{
qof_instance_get (QOF_INSTANCE (split), qof_instance_get (QOF_INSTANCE (split),
"sx-credit-formula", &formula, "sx-credit-formula", &formula,
NULL); NULL);
}
return formula; return formula;