From: Filipe Brandenburger Date: Mon, 31 Aug 2015 02:40:44 +0000 (-0700) Subject: extract_first_word: Refactor EXTRACT_DONT_COALESCE_SEPARATORS handling X-Git-Tag: v226.4~1^2~100 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=1308667689580277d99a7fcdf8769752986d31eb;ds=sidebyside extract_first_word: Refactor EXTRACT_DONT_COALESCE_SEPARATORS handling Refactor allocation of the result string to the top, since it is currently done in both branches of the condition. Remove unreachable code checking for EXTRACT_DONT_COALESCE_SEPARATORS when state == SEPARATOR (the only place where SEPARATOR is assigned to state follows a check for EXTRACT_DONT_COALESCE_SEPARATORS that jumps to the end of the function.) Tested by running test-util successfully. Follow up to: 206644aedeb8859801051ac170ec562c6a113a79 --- diff --git a/src/basic/util.c b/src/basic/util.c index fbd6ff5d9..0d45b631f 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -5844,15 +5844,14 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra switch (state) { case START: - if (c == 0) { - if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; + 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)) { + else if (strchr(separators, c)) { if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) { - if (!GREEDY_REALLOC(s, allocated, sz+1)) - return -ENOMEM; (*p) ++; goto finish_force_next; } @@ -5981,8 +5980,6 @@ end_escape: case SEPARATOR: if (c == 0) goto finish_force_terminate; - if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) - goto finish_force_next; if (!strchr(separators, c)) goto finish; break;