diff options
Diffstat (limited to 'src/strv.c')
-rw-r--r-- | src/strv.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/strv.c b/src/strv.c index a52440d832..92851b2233 100644 --- a/src/strv.c +++ b/src/strv.c @@ -482,8 +482,8 @@ static bool env_match(const char *t, const char *pattern) { } char **strv_env_delete(char **x, unsigned n_lists, ...) { - size_t n = 0, i = 0; - char **l, **k, **r, **j; + size_t n, i = 0; + char **k, **r; va_list ap; /* Deletes every entry from x that is mentioned in the other @@ -491,29 +491,34 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) { n = strv_length(x); - if (!(r = new(char*, n+1))) + r = new(char*, n+1); + if (!r) return NULL; STRV_FOREACH(k, x) { + unsigned v; + va_start(ap, n_lists); + for (v = 0; v < n_lists; v++) { + char **l, **j; - for (i = 0; i < n_lists; i++) { l = va_arg(ap, char**); STRV_FOREACH(j, l) if (env_match(*k, *j)) - goto delete; + goto skip; } - va_end(ap); - if (!(r[i++] = strdup(*k))) { + r[i] = strdup(*k); + if (!r[i]) { strv_free(r); return NULL; } + i++; continue; - delete: + skip: va_end(ap); } |