]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: remove unnecessary variable 18890/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 Mar 2021 15:36:37 +0000 (16:36 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 6 Mar 2021 08:32:18 +0000 (09:32 +0100)
Also use structued initialization in one more place, use '\0' for NUL bytes,
and move variable to the right block (the code was OK, but it is strange to
have 'char *value' defined in a different scope then 'size_t value_allocated').

src/libsystemd/sd-bus/bus-match.c

index 71a6cd1318e4dab4fc17f7eeee2e738da19467f8..96b50aeaed6360d4e7275f546cee37b8b10c00dd 100644 (file)
@@ -710,35 +710,34 @@ int bus_match_parse(
                 struct bus_match_component **ret_components,
                 unsigned *ret_n_components) {
 
-        const char *p = match;
         struct bus_match_component *components = NULL;
         size_t components_allocated = 0;
         unsigned n_components = 0;
-        _cleanup_free_ char *value = NULL;
         int r;
 
         assert(match);
         assert(ret_components);
         assert(ret_n_components);
 
-        while (*p != 0) {
+        while (*match != '\0') {
                 const char *eq, *q;
                 enum bus_match_node_type t;
                 unsigned j = 0;
+                _cleanup_free_ char *value = NULL;
                 size_t value_allocated = 0;
                 bool escaped = false, quoted;
                 uint8_t u;
 
                 /* Avahi's match rules appear to include whitespace, skip over it */
-                p += strspn(p, " ");
+                match += strspn(match, " ");
 
-                eq = strchr(p, '=');
+                eq = strchr(match, '=');
                 if (!eq) {
                         r = -EINVAL;
                         goto fail;
                 }
 
-                t = bus_match_node_type_from_string(p, eq - p);
+                t = bus_match_node_type_from_string(match, eq - match);
                 if (t < 0) {
                         r = -EINVAL;
                         goto fail;
@@ -748,14 +747,14 @@ int bus_match_parse(
 
                 for (q = eq + 1 + quoted;; q++) {
 
-                        if (*q == 0) {
+                        if (*q == '\0') {
 
                                 if (quoted) {
                                         r = -EINVAL;
                                         goto fail;
                                 } else {
                                         if (value)
-                                                value[j] = 0;
+                                                value[j] = '\0';
                                         break;
                                 }
                         }
@@ -769,14 +768,13 @@ int bus_match_parse(
                                 if (quoted) {
                                         if (*q == '\'') {
                                                 if (value)
-                                                        value[j] = 0;
+                                                        value[j] = '\0';
                                                 break;
                                         }
                                 } else {
                                         if (*q == ',') {
                                                 if (value)
-                                                        value[j] = 0;
-
+                                                        value[j] = '\0';
                                                 break;
                                         }
                                 }
@@ -813,10 +811,11 @@ int bus_match_parse(
                         goto fail;
                 }
 
-                components[n_components].type = t;
-                components[n_components].value_str = TAKE_PTR(value);
-                components[n_components].value_u8 = u;
-                n_components++;
+                components[n_components++] = (struct bus_match_component) {
+                        .type = t,
+                        .value_str = TAKE_PTR(value),
+                        .value_u8 = u,
+                };
 
                 if (q[quoted] == 0)
                         break;
@@ -826,7 +825,7 @@ int bus_match_parse(
                         goto fail;
                 }
 
-                p = q + 1 + quoted;
+                match = q + 1 + quoted;
         }
 
         /* Order the whole thing, so that we always generate the same tree */