r21690 - gnucash/trunk/src/gnome - Avoid risk on a rare crash after r21680.

Geert Janssens gjanssens at code.gnucash.org
Thu Dec 8 12:11:52 EST 2011


Author: gjanssens
Date: 2011-12-08 12:11:52 -0500 (Thu, 08 Dec 2011)
New Revision: 21690
Trac: http://svn.gnucash.org/trac/changeset/21690

Modified:
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
Log:
Avoid risk on a rare crash after r21680.
Some data files may only have filter[0] in which case filter[1] is NULL
and filter[2] invalid. A rare situation, but I have one test data file
consistently crashing on this.
I also took the opportunity to convert from strcmp to g_strcmp0.

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2011-12-08 17:11:43 UTC (rev 21689)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2011-12-08 17:11:52 UTC (rev 21690)
@@ -930,7 +930,7 @@
     
         gnc_split_reg_set_sort_type(priv->gsr, SortTypefromString(order));
     
-        if (order && (strcmp (order, DEFAULT_SORT_ORDER) != 0))
+        if (order && (g_strcmp0 (order, DEFAULT_SORT_ORDER) != 0))
             priv->sd.save_order = TRUE;
     
         priv->sd.original_save_order = priv->sd.save_order;
@@ -945,25 +945,25 @@
     
         priv->fd.cleared_match = (gint)g_ascii_strtoll( filter[0], NULL, 16 );
     
-        if (filter[0] && (strcmp (filter[0], DEFAULT_FILTER) != 0))
+        if (filter[0] && (g_strcmp0 (filter[0], DEFAULT_FILTER) != 0))
             filter_changed = filter_changed + 1;
     
-        if (filter[1] && (strcmp (filter[1],"0") != 0 ))
+        if (filter[1] && (g_strcmp0 (filter[1],"0") != 0 ))
         {
             PINFO("Loaded Filter Start Date is %s", filter[1]);
     
             priv->fd.start_time = gnc_plugin_page_register_filter_dmy2time( filter[1] );
             priv->fd.start_time = gnc_timet_get_day_start(priv->fd.start_time);
             filter_changed = filter_changed + 1;
-        }
+
+            if (filter[2] && (g_strcmp0 (filter[2],"0") != 0 ))
+            {
+                PINFO("Loaded Filter End Date is %s", filter[2]);
     
-        if (filter[2] && (strcmp (filter[2],"0") != 0 ))
-        {
-            PINFO("Loaded Filter End Date is %s", filter[2]);
-
-            priv->fd.end_time = gnc_plugin_page_register_filter_dmy2time( filter[2] );
-            priv->fd.end_time = gnc_timet_get_day_end(priv->fd.end_time);
-            filter_changed = filter_changed + 1;
+                priv->fd.end_time = gnc_plugin_page_register_filter_dmy2time( filter[2] );
+                priv->fd.end_time = gnc_timet_get_day_end(priv->fd.end_time);
+                filter_changed = filter_changed + 1;
+            }
         }
     
         if(filter_changed != 0)
@@ -1426,6 +1426,7 @@
         default:
             break;
         }
+        break;
 
     default:
         break;
@@ -1504,7 +1505,7 @@
     {
         default_filter = g_strdup_printf("%s,%s,%s", DEFAULT_FILTER, "0", "0");
     
-        if (!filter || (strcmp (filter, default_filter) == 0))
+        if (!filter || (g_strcmp0 (filter, default_filter) == 0))
             xaccAccountSetFilter (leader, NULL);
         else
             xaccAccountSetFilter (leader, filter);
@@ -1557,7 +1558,7 @@
     
     if (leader != NULL)
     {
-        if (!sort_order || (strcmp (sort_order, DEFAULT_SORT_ORDER) == 0))
+        if (!sort_order || (g_strcmp0 (sort_order, DEFAULT_SORT_ORDER) == 0))
             xaccAccountSetSortOrder (leader, NULL);
         else
             xaccAccountSetSortOrder (leader, sort_order);
@@ -1919,7 +1920,7 @@
     value = CLEARED_NONE;
     for (i = 0; status_actions[i].action_name; i++)
     {
-        if (strcmp(name, status_actions[i].action_name) == 0)
+        if (g_strcmp0(name, status_actions[i].action_name) == 0)
         {
             value = status_actions[i].value;
             break;
@@ -2138,7 +2139,7 @@
     }
 
     name = gtk_buildable_get_name(GTK_BUILDABLE(radio));
-    active = ( strcmp(name, g_strdup("start_date_choose")) == 0 ? 1 : 0 );
+    active = ( g_strcmp0(name, g_strdup("start_date_choose")) == 0 ? 1 : 0 );
     gtk_widget_set_sensitive(priv->fd.start_date, active);
     get_filter_times(page);
     gnc_ppr_update_date_query(page);
@@ -2185,7 +2186,7 @@
     }
 
     name = gtk_buildable_get_name(GTK_BUILDABLE(radio));
-    active = ( strcmp(name, g_strdup("end_date_choose")) == 0 ? 1 : 0 );
+    active = ( g_strcmp0(name, g_strdup("end_date_choose")) == 0 ? 1 : 0 );
     gtk_widget_set_sensitive(priv->fd.end_date, active);
     get_filter_times(page);
     gnc_ppr_update_date_query(page);



More information about the gnucash-changes mailing list