]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
extract-word: Skip coalesced separators in place 1793/head
authorFilipe Brandenburger <filbranden@google.com>
Fri, 6 Nov 2015 05:57:26 +0000 (21:57 -0800)
committerFilipe Brandenburger <filbranden@google.com>
Fri, 6 Nov 2015 05:57:26 +0000 (21:57 -0800)
Just skip them in place, instead of setting separator=true. We only do
that in a single place (while finding a separator outside of quote or
backslash states) so we don't really need a separate state for it.

Tested that no regressions were introduced in test-extract-word. Ran a
full `make check` and also installed the binaries on a test system and
did not see any issues related to parsing unit files or starting units
after a reboot.

src/basic/extract-word.c

index 67511a32e182fa80ea4bcfb4d6871c7c24dfd7ca..ff6d211ef4c6a01fc0ca1b05e685dcd0e3dab707 100644 (file)
@@ -34,7 +34,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
 
         char quote = 0;                 /* 0 or ' or " */
         bool backslash = false;         /* whether we've just seen a backslash */
-        bool separator = false;         /* whether we've just seen a separator */
 
         assert(p);
         assert(ret);
@@ -140,14 +139,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
                                 }
                         }
 
-                } else if (separator) {
-                        for (;; (*p) ++, c = **p) {
-                                if (c == 0)
-                                        goto finish_force_terminate;
-                                if (!strchr(separators, c))
-                                        goto finish;
-                        }
-
                 } else {
                         for (;; (*p) ++, c = **p) {
                                 if (c == 0)
@@ -163,8 +154,15 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
                                                 (*p) ++;
                                                 goto finish_force_next;
                                         }
-                                        separator = true;
-                                        break;
+                                        /* Skip additional coalesced separators. */
+                                        for (;; (*p) ++, c = **p) {
+                                                if (c == 0)
+                                                        goto finish_force_terminate;
+                                                if (!strchr(separators, c))
+                                                        break;
+                                        }
+                                        goto finish;
+
                                 } else {
                                         if (!GREEDY_REALLOC(s, allocated, sz+2))
                                                 return -ENOMEM;