]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
env-util: use strextendn() instead of strnappend() where appropriate
authorMike Yuan <me@yhndnzj.com>
Mon, 10 Feb 2025 18:04:29 +0000 (19:04 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 10 Feb 2025 18:39:21 +0000 (19:39 +0100)
src/basic/env-util.c

index 99ce1a1842023fc466d1d71f5faf190231f47297..09c8e7c28f802075b8320d81d1921be7f46f38f3 100644 (file)
@@ -695,7 +695,7 @@ int replace_env_full(
         _cleanup_strv_free_ char **unset_variables = NULL, **bad_variables = NULL;
         const char *e, *word = format, *test_value = NULL; /* test_value is initialized to appease gcc */
         _cleanup_free_ char *s = NULL;
-        char ***pu, ***pb, *k;
+        char ***pu, ***pb;
         size_t i, len = 0; /* len is initialized to appease gcc */
         int nest = 0, r;
 
@@ -717,33 +717,24 @@ int replace_env_full(
 
                 case CURLY:
                         if (*e == '{') {
-                                k = strnappend(s, word, e-word-1);
-                                if (!k)
+                                if (!strextendn(&s, word, e-word-1))
                                         return -ENOMEM;
 
-                                free_and_replace(s, k);
-
                                 word = e-1;
                                 state = VARIABLE;
                                 nest++;
 
                         } else if (*e == '$') {
-                                k = strnappend(s, word, e-word);
-                                if (!k)
+                                if (!strextendn(&s, word, e-word))
                                         return -ENOMEM;
 
-                                free_and_replace(s, k);
-
                                 word = e+1;
                                 state = WORD;
 
                         } else if (FLAGS_SET(flags, REPLACE_ENV_ALLOW_BRACELESS) && strchr(VALID_BASH_ENV_NAME_CHARS, *e)) {
-                                k = strnappend(s, word, e-word-1);
-                                if (!k)
+                                if (!strextendn(&s, word, e-word-1))
                                         return -ENOMEM;
 
-                                free_and_replace(s, k);
-
                                 word = e-1;
                                 state = VARIABLE_RAW;