r20624 - gnucash/trunk/src - Owner tree: fix crash when modifying owner name

Geert Janssens gjanssens at code.gnucash.org
Wed May 11 17:51:45 EDT 2011


Author: gjanssens
Date: 2011-05-11 17:51:45 -0400 (Wed, 11 May 2011)
New Revision: 20624
Trac: http://svn.gnucash.org/trac/changeset/20624

Modified:
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
   gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c
Log:
Owner tree: fix crash when modifying owner name

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2011-05-11 21:51:36 UTC (rev 20623)
+++ gnucash/trunk/src/engine/gncOwner.c	2011-05-11 21:51:45 UTC (rev 20624)
@@ -394,6 +394,14 @@
     return (a->owner.undefined == b->owner.undefined);
 }
 
+int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b)
+{
+    if (gncOwnerEqual (a, b))
+        return 0;
+    else
+        return 1;
+}
+
 const char * gncOwnerGetID (const GncOwner *owner)
 {
     if (!owner) return NULL;

Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	2011-05-11 21:51:36 UTC (rev 20623)
+++ gnucash/trunk/src/engine/gncOwner.h	2011-05-11 21:51:45 UTC (rev 20624)
@@ -130,9 +130,18 @@
 /** @} */
 
 void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
-gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
-int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
 
+/** \name Comparison routines.
+ @{
+ */
+gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b); /** Check if both objects refer to the same owner type
+                                                                   if and the owner reference points to the same
+                                                                   {vendor/customer/employee} in memory */
+int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b); /** Same as gncOwnerEqual, but returns 0 if
+                                                                     equal to be used as a GList custom compare function */
+int gncOwnerCompare (const GncOwner *a, const GncOwner *b); /** Sort on name */
+/** @} */
+
 /** Get the GncGUID of the immediate owner */
 const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
 GncGUID gncOwnerRetGUID (GncOwner *owner);

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c	2011-05-11 21:51:36 UTC (rev 20623)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c	2011-05-11 21:51:45 UTC (rev 20624)
@@ -941,13 +941,13 @@
     gnc_leave_return_val_if_fail ((owner != NULL), FALSE);
     gnc_leave_return_val_if_fail ((iter != NULL), FALSE);
 
-    iter->user_data = owner;
-    iter->stamp = model->stamp;
 
     priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
-    owner_in_list = g_list_find (priv->owner_list, (gconstpointer)owner);
+    owner_in_list = g_list_find_custom (priv->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
     if (owner_in_list)
     {
+        iter->stamp = model->stamp;
+        iter->user_data = owner_in_list->data;
         iter->user_data2 = GINT_TO_POINTER (g_list_position (priv->owner_list, owner_in_list));
         iter->user_data3 = NULL;
         LEAVE("iter %s", iter_to_string (iter));
@@ -955,6 +955,8 @@
     }
     else
     {
+        iter->stamp = 0;
+        iter->user_data = NULL;
         LEAVE("Owner not found in list");
         return FALSE;
     }
@@ -1056,13 +1058,13 @@
           entity, event_type, model, ed);
     priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
 
-    qofOwnerSetEntity (&owner, entity);
-    if (qof_instance_get_book (QOF_INSTANCE(&owner)) != priv->book)
+    if (qof_instance_get_book (entity) != priv->book)
     {
         LEAVE("not in this book");
         return;
     }
-    if (!g_list_find (priv->owner_list, (gconstpointer)&owner))
+    qofOwnerSetEntity (&owner, entity);
+    if (!gnc_tree_model_owner_get_iter_from_owner (model, &owner, &iter))
     {
         LEAVE("not in this model");
         return;
@@ -1073,7 +1075,7 @@
     case QOF_EVENT_ADD:
         /* Tell the filters/views where the new owner was added. */
         DEBUG("add owner %p (%s)", &owner, gncOwnerGetName(&owner));
-        path = gnc_tree_model_owner_get_path_from_owner(model, &owner);
+        path = gnc_tree_model_owner_get_path(GTK_TREE_MODEL(model), &iter);
         if (!path)
         {
             DEBUG("can't generate path");
@@ -1106,7 +1108,7 @@
 
     case QOF_EVENT_MODIFY:
         DEBUG("modify  owner %p (%s)", &owner, gncOwnerGetName(&owner));
-        path = gnc_tree_model_owner_get_path_from_owner(model, &owner);
+        path = gnc_tree_model_owner_get_path(GTK_TREE_MODEL(model), &iter);
         if (!path)
         {
             DEBUG("can't generate path");



More information about the gnucash-changes mailing list