From: Zbigniew Jędrzejewski-Szmek Date: Fri, 5 Mar 2021 15:36:37 +0000 (+0100) Subject: sd-bus: remove unnecessary variable X-Git-Tag: v248-rc3~42^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F18890%2Fhead;p=thirdparty%2Fsystemd.git sd-bus: remove unnecessary variable 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'). --- diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 71a6cd1318e..96b50aeaed6 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -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 */