]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nulstr-util: don't use 'r' for anything but integer return values
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Nov 2022 21:07:43 +0000 (22:07 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Nov 2022 08:39:08 +0000 (17:39 +0900)
src/basic/nulstr-util.c

index 2da64fcbe9909c18a4e585efcaa72a7e75e7ff61..67226d208c284608a4123bb6a932cf84e9d0c282 100644 (file)
@@ -55,16 +55,18 @@ char** strv_parse_nulstr(const char *s, size_t l) {
 }
 
 char** strv_split_nulstr(const char *s) {
-        _cleanup_strv_free_ char **r = NULL;
+        _cleanup_strv_free_ char **l = NULL;
+
+        /* This parses a nulstr, without specification of size, and stops at an empty string. This cannot
+         * parse nulstrs with embedded empty strings hence, as an empty string is an end marker. Use
+         * strv_parse_nulstr() above to parse a nulstr with embedded empty strings (which however requires a
+         * size to be specified) */
 
         NULSTR_FOREACH(i, s)
-                if (strv_extend(&r, i) < 0)
+                if (strv_extend(&l, i) < 0)
                         return NULL;
 
-        if (!r)
-                return strv_new(NULL);
-
-        return TAKE_PTR(r);
+        return l ? TAKE_PTR(l) : strv_new(NULL);
 }
 
 int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {