summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2015-11-03 20:13:11 -0800
committerFilipe Brandenburger <filbranden@google.com>2015-11-05 21:19:54 -0800
commitb85e1c2534ca3b396c2aaa7de384995b42d12e1b (patch)
tree4556fcf59428653491ba82b690677946b3c67821 /src
parenta6bff4a7428b9539d85618e3c91fcb60be93f3fa (diff)
extract-word: move start block outside the for loop
This block runs once before all the other handling, so move it outside the main loop and put it in its own loop until it's finished doing its job. Tested by confirming `make check` (and particularly test-extract-word) still passes and by booting a system with binaries including this commit.
Diffstat (limited to 'src')
-rw-r--r--src/basic/extract-word.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c
index 6721b85c0a..23e3d557c0 100644
--- a/src/basic/extract-word.c
+++ b/src/basic/extract-word.c
@@ -29,12 +29,12 @@
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {
_cleanup_free_ char *s = NULL;
size_t allocated = 0, sz = 0;
+ char c;
int r;
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 */
- bool start = true; /* false means we're looking at a value */
assert(p);
assert(ret);
@@ -51,31 +51,30 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
* (because of an uneven number of quotes or similar), leaves
* the pointer *p at the first invalid character. */
- for (;;) {
- char c = **p;
+ if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
+ if (!GREEDY_REALLOC(s, allocated, sz+1))
+ return -ENOMEM;
- if (start) {
+ for (;;) {
+ c = **p;
+ if (c == 0)
+ goto finish_force_terminate;
+ else if (strchr(separators, c)) {
+ (*p) ++;
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
- if (!GREEDY_REALLOC(s, allocated, sz+1))
- return -ENOMEM;
-
- if (c == 0)
- goto finish_force_terminate;
- else if (strchr(separators, c)) {
- (*p) ++;
- if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
- goto finish_force_next;
- continue;
- }
-
+ 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),
* allocate it here. */
if (!GREEDY_REALLOC(s, allocated, sz+1))
return -ENOMEM;
-
- start = false;
+ break;
}
+ }
+
+ for (;;) {
+ c = **p;
if (backslash) {
if (!GREEDY_REALLOC(s, allocated, sz+7))