mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-05 09:17:44 +03:00
extract_first_word: Refactor allocation in empty argument case
This covers the case where an argument is an empty string, such as ''.
Instead of allocating the empty string in the individual conditions when
state == VALUE, just always allocate it at the end of state == START, at
which point we know we will have an argument.
Tested that test-util keeps passing after the refactor.
Follow up to: 14e685c29d
This commit is contained in:
parent
40ec276fdf
commit
d3ef6c5560
@ -5769,25 +5769,25 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
state = VALUE;
|
||||
/* fallthrough */
|
||||
|
||||
case VALUE:
|
||||
if (c == 0)
|
||||
goto finish_force_terminate;
|
||||
else if (c == '\'' && (flags & EXTRACT_QUOTES)) {
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+1))
|
||||
return -ENOMEM;
|
||||
|
||||
else if (c == '\'' && (flags & EXTRACT_QUOTES))
|
||||
state = SINGLE_QUOTE;
|
||||
} else if (c == '\\')
|
||||
else if (c == '\\')
|
||||
state = VALUE_ESCAPE;
|
||||
else if (c == '\"' && (flags & EXTRACT_QUOTES)) {
|
||||
if (!GREEDY_REALLOC(s, allocated, sz+1))
|
||||
return -ENOMEM;
|
||||
|
||||
else if (c == '\"' && (flags & EXTRACT_QUOTES))
|
||||
state = DOUBLE_QUOTE;
|
||||
} else if (strchr(separators, c)) {
|
||||
else if (strchr(separators, c)) {
|
||||
if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
|
||||
(*p) ++;
|
||||
goto finish_force_next;
|
||||
|
Loading…
Reference in New Issue
Block a user