]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
extract-word: increment pointer p and keep c in sync in for loop
authorFilipe Brandenburger <filbranden@google.com>
Fri, 6 Nov 2015 05:41:04 +0000 (21:41 -0800)
committerFilipe Brandenburger <filbranden@google.com>
Fri, 6 Nov 2015 05:41:04 +0000 (21:41 -0800)
This will make it easier to use inner loops to keep looping in the same
state, by just updating p and c in the same way in the inner loops.

Tested that no regressions were created in test-extract-word.

src/basic/extract-word.c

index b08851b89bc3381f646e7d20ae2eed6f1f226f79..b0056a8485713316b34364b25be194b1e687fdd9 100644 (file)
@@ -42,6 +42,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
         /* Bail early if called after last value or with no input */
         if (!*p)
                 goto finish_force_terminate;
+        c = **p;
 
         if (!separators)
                 separators = WHITESPACE;
@@ -55,14 +56,14 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
                 if (!GREEDY_REALLOC(s, allocated, sz+1))
                         return -ENOMEM;
 
-        for (;;) {
-                c = **p;
+        for (;; (*p) ++, c = **p) {
                 if (c == 0)
                         goto finish_force_terminate;
                 else if (strchr(separators, c)) {
-                        (*p) ++;
-                        if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
+                        if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
+                                (*p) ++;
                                 goto finish_force_next;
+                        }
                 } else {
                         /* We found a non-blank character, so we will always
                          * want to return a string (even if it is empty),
@@ -73,9 +74,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
                 }
         }
 
-        for (;;) {
-                c = **p;
-
+        for (;; (*p) ++, c = **p) {
                 if (backslash) {
                         if (!GREEDY_REALLOC(s, allocated, sz+7))
                                 return -ENOMEM;
@@ -163,8 +162,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
                                 s[sz++] = c;
                         }
                 }
-
-                (*p) ++;
         }
 
 finish_force_terminate: