[Gnucash-changes] Clean up potential SEGV on NULL return.

Joshua Sled jsled at cvs.gnucash.org
Mon May 31 11:52:30 EDT 2004


Log Message:
-----------
Clean up potential SEGV on NULL return.
Fix other instance of xaccGUIDType call while we're in the file.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/gnome:
        top-level.c

Revision Data
-------------
Index: top-level.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/top-level.c,v
retrieving revision 1.140.4.11
retrieving revision 1.140.4.12
diff -Lsrc/gnome/top-level.c -Lsrc/gnome/top-level.c -u -r1.140.4.11 -r1.140.4.12
--- src/gnome/top-level.c
+++ src/gnome/top-level.c
@@ -167,7 +167,6 @@
   else if (strncmp ("guid=", location, 5) == 0)
   {
     GUID guid;
-    GNCIdType id_type;
     QofEntity *qofEnt;
 
     if (!string_to_guid (location + 5, &guid))
@@ -176,23 +175,23 @@
       return FALSE;
     }
 
-    //id_type = xaccGUIDType (&guid, gnc_get_current_book ());
-    //id_type = 
     qofEnt = qof_book_get_entity_by_guid( gnc_get_current_book(), &guid );
-    id_type = qofEnt->e_type;
-    if (id_type == GNC_ID_NONE || !safe_strcmp (id_type, GNC_ID_NULL))
+    if ( (qofEnt == NULL)
+         || (qofEnt->e_type == GNC_ID_NONE)
+         || !safe_strcmp( qofEnt->e_type, GNC_ID_NULL ))
     {
         result->error_message = g_strdup_printf (_("No such entity: %s"),
                                                  location);
         return FALSE;
     }
-    else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
+
+    else if (!safe_strcmp (qofEnt->e_type, GNC_ID_ACCOUNT))
     {
         account = xaccAccountLookup (&guid, gnc_get_current_book ());
 	page = gnc_plugin_page_register_new (account, FALSE);
 	gnc_main_window_open_page (NULL, page);
     }
-    else if (!safe_strcmp (id_type, GNC_ID_TRANS))
+    else if (!safe_strcmp (qofEnt->e_type, GNC_ID_TRANS))
     {
         trans = xaccTransLookup (&guid, gnc_get_current_book ());
         split = NULL;
@@ -215,7 +214,7 @@
 	page = gnc_plugin_page_register_new (account, FALSE);
 	gnc_main_window_open_page (NULL, page);
     }
-    else if (!safe_strcmp (id_type, GNC_ID_SPLIT))
+    else if (!safe_strcmp (qofEnt->e_type, GNC_ID_SPLIT))
     {
         split = xaccSplitLookup (&guid, gnc_get_current_book ());
         if (!split)
@@ -264,7 +263,7 @@
   if (strncmp ("guid=", location, 5) == 0)
   {
       GUID guid;
-      GNCIdType id_type;
+      QofEntity *qofEnt;
 
       if (!string_to_guid (location + 5, &guid))
       {
@@ -272,16 +271,20 @@
 	  return FALSE;
       }
 
-      id_type = xaccGUIDType (&guid, gnc_get_current_book ());
-      if (id_type == GNC_ID_NONE || safe_strcmp (id_type, GNC_ID_PRICE))
+      qofEnt = qof_book_get_entity_by_guid( gnc_get_current_book(),
+                                            &guid );
+
+      if ( qofEnt == NULL
+           || qofEnt->e_type == GNC_ID_NONE
+           || safe_strcmp (qofEnt->e_type, GNC_ID_PRICE))
       {
           result->error_message =
 	    g_strdup_printf (_("Unsupported entity type: %s"), location);
 	  return FALSE;
       }
       if (!gnc_price_edit_by_guid (NULL, &guid)) {
-          result->error_message = g_strdup_printf (_("No such entity: %s"),
-						 location);
+          result->error_message = g_strdup_printf(_("No such entity: %s"),
+                                                  location);
 	  return FALSE;
       }
   }


More information about the gnucash-changes mailing list