chiark / gitweb /
strv: fix counting in strv_env_delete()
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Aug 2011 23:10:13 +0000 (01:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Aug 2011 23:10:13 +0000 (01:10 +0200)
src/strv.c

index a52440d..92851b2 100644 (file)
@@ -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);
         }