[PATCH 2/5] Simplified locate_attributes () in config-parser.c

Pekka Pessi Pekka.Pessi at nokia.com
Fri Jun 4 09:58:43 PDT 2010


Expat takes care of checking for duplicate attributes.
---
 bus/config-parser.c |   48 +++++++++++++-----------------------------------
 1 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/bus/config-parser.c b/bus/config-parser.c
index 44e9a55..1a091df 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -567,14 +567,11 @@ locate_attributes (BusConfigParser  *parser,
   int n_attrs;
 #define MAX_ATTRS 24
   LocateAttr attrs[MAX_ATTRS];
-  dbus_bool_t retval;
-  int i;
+  int i, j;
 
   _dbus_assert (first_attribute_name != NULL);
   _dbus_assert (first_attribute_retloc != NULL);
 
-  retval = TRUE;
-
   n_attrs = 1;
   attrs[0].name = first_attribute_name;
   attrs[0].retloc = first_attribute_retloc;
@@ -604,47 +601,28 @@ locate_attributes (BusConfigParser  *parser,
   i = 0;
   while (attribute_names[i])
     {
-      int j;
-      dbus_bool_t found;
-      
-      found = FALSE;
-      j = 0;
-      while (j < n_attrs)
+      for (j = 0; j < n_attrs; ++j)
         {
-          if (strcmp (attrs[j].name, attribute_names[i]) == 0)
-            {
-              retloc = attrs[j].retloc;
-
-              if (*retloc != NULL)
-                {
-                  dbus_set_error (error, DBUS_ERROR_FAILED,
-                                  "Attribute \"%s\" repeated twice on the same <%s> element",
-                                  attrs[j].name, element_name);
-                  retval = FALSE;
-                  goto out;
-                }
+          name = attrs[j].name;
+          retloc = attrs[j].retloc;
 
+          if (strcmp (name, attribute_names[i]) == 0)
+            {
               *retloc = attribute_values[i];
-              found = TRUE;
+              goto found;
             }
-
-          ++j;
         }
 
-      if (!found)
-        {
-          dbus_set_error (error, DBUS_ERROR_FAILED,
-                          "Attribute \"%s\" is invalid on <%s> element in this context",
-                          attribute_names[i], element_name);
-          retval = FALSE;
-          goto out;
-        }
+      dbus_set_error (error, DBUS_ERROR_FAILED,
+                      "Attribute \"%s\" is invalid on <%s> element in this context",
+                      attribute_names[i], element_name);
+      return FALSE;
 
+    found:
       ++i;
     }
 
- out:
-  return retval;
+  return TRUE;
 }
 
 static dbus_bool_t
-- 
1.6.3.3



More information about the dbus mailing list