]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strv: drop strv_join_quoted() (#8057)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Feb 2018 09:11:02 +0000 (18:11 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Feb 2018 09:11:02 +0000 (10:11 +0100)
The function `strv_join_quoted()` is now not used, and has a bug
in the buffer size calculation when the strings needs to escaped,
as reported in #8056.
So, let's remove the function.

Closes #8056.

src/basic/strv.c
src/basic/strv.h
src/test/test-strv.c

index 54c701aee2a6259bbe9333e21681b0f818272249..1103245a3663a912311012f46810560b9b38cfaf 100644 (file)
@@ -393,42 +393,6 @@ char *strv_join(char **l, const char *separator) {
         return r;
 }
 
-char *strv_join_quoted(char **l) {
-        char *buf = NULL;
-        char **s;
-        size_t allocated = 0, len = 0;
-
-        STRV_FOREACH(s, l) {
-                /* assuming here that escaped string cannot be more
-                 * than twice as long, and reserving space for the
-                 * separator and quotes.
-                 */
-                _cleanup_free_ char *esc = NULL;
-                size_t needed;
-
-                if (!GREEDY_REALLOC(buf, allocated,
-                                    len + strlen(*s) * 2 + 3))
-                        goto oom;
-
-                esc = cescape(*s);
-                if (!esc)
-                        goto oom;
-
-                needed = snprintf(buf + len, allocated - len, "%s\"%s\"",
-                                  len > 0 ? " " : "", esc);
-                assert(needed < allocated - len);
-                len += needed;
-        }
-
-        if (!buf)
-                buf = malloc0(1);
-
-        return buf;
-
- oom:
-        return mfree(buf);
-}
-
 int strv_push(char ***l, char *value) {
         char **c;
         unsigned n, m;
index 0ed6b74330c6926c58879a373ff820866dc294b9..75369d29cb3922f1c9057a028aed3069ecf8a1ca 100644 (file)
@@ -86,7 +86,6 @@ char **strv_split_newlines(const char *s);
 int strv_split_extract(char ***t, const char *s, const char *separators, ExtractFlags flags);
 
 char *strv_join(char **l, const char *separator);
-char *strv_join_quoted(char **l);
 
 char **strv_parse_nulstr(const char *s, size_t l);
 char **strv_split_nulstr(const char *s);
index aec00eb817b138523e4f2e6a33a78f21470ef865..f78b1bcd4643baa6056fcd15432ed560c60cbbf3 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include "alloc-util.h"
+#include "escape.h"
 #include "specifier.h"
 #include "string-util.h"
 #include "strv.h"
@@ -102,36 +103,6 @@ static const char* const input_table_one_empty[] = {
 };
 
 
-static const char* const input_table_quotes[] = {
-        "\"",
-        "'",
-        "\"\"",
-        "\\",
-        "\\\\",
-        NULL,
-};
-#define QUOTES_STRING                            \
-        "\"\\\"\" "                              \
-        "\"\\\'\" "                              \
-        "\"\\\"\\\"\" "                          \
-        "\"\\\\\" "                              \
-        "\"\\\\\\\\\""
-
-static const char * const input_table_spaces[] = {
-        " ",
-        "' '",
-        "\" ",
-        " \"",
-        " \\\\ ",
-        NULL,
-};
-#define SPACES_STRING                           \
-        "\" \" "                                \
-        "\"\\' \\'\" "                          \
-        "\"\\\" \" "                            \
-        "\" \\\"\" "                            \
-        "\" \\\\\\\\ \""
-
 static void test_strv_find(void) {
         assert_se(strv_find((char **)input_table_multiple, "three"));
         assert_se(!strv_find((char **)input_table_multiple, "four"));
@@ -193,28 +164,6 @@ static void test_strv_join(void) {
         assert_se(streq(w, ""));
 }
 
-static void test_strv_quote_unquote(const char* const *split, const char *quoted) {
-        _cleanup_free_ char *p;
-        _cleanup_strv_free_ char **s = NULL;
-        char **t;
-        int r;
-
-        p = strv_join_quoted((char **)split);
-        assert_se(p);
-        printf("-%s- --- -%s-\n", p, quoted); /* fprintf deals with NULL, puts does not */
-        assert_se(p);
-        assert_se(streq(p, quoted));
-
-        r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
-        assert_se(r == (int) strv_length(s));
-        assert_se(s);
-        STRV_FOREACH(t, s) {
-                assert_se(*t);
-                assert_se(streq(*t, *split));
-                split++;
-        }
-}
-
 static void test_strv_unquote(const char *quoted, char **list) {
         _cleanup_strv_free_ char **s;
         _cleanup_free_ char *j;
@@ -738,14 +687,6 @@ int main(int argc, char *argv[]) {
         test_strv_find_startswith();
         test_strv_join();
 
-        test_strv_quote_unquote(input_table_multiple, "\"one\" \"two\" \"three\"");
-        test_strv_quote_unquote(input_table_one, "\"one\"");
-        test_strv_quote_unquote(input_table_none, "");
-        test_strv_quote_unquote(input_table_one_empty, "\"\"");
-        test_strv_quote_unquote(input_table_two_empties, "\"\" \"\"");
-        test_strv_quote_unquote(input_table_quotes, QUOTES_STRING);
-        test_strv_quote_unquote(input_table_spaces, SPACES_STRING);
-
         test_strv_unquote("    foo=bar     \"waldo\"    zzz    ", STRV_MAKE("foo=bar", "waldo", "zzz"));
         test_strv_unquote("", STRV_MAKE_EMPTY);
         test_strv_unquote(" ", STRV_MAKE_EMPTY);