]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: drop unnecessary initialization
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 12:38:23 +0000 (14:38 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 13:12:18 +0000 (15:12 +0200)
cunescape() sets output on success, so initialization is not necessary. There
was no comment, but I think they may have been added because the compiler
wasn't convinced that the return value is non-negative on success. It could
have been confused by the int return type on escape*(), which was changed by
the one of preceeding commits to ssize_t, or by the length calculation, so add
an assert to help the compiler.

For some reason coverity thinks the output can be leaked here (CID #1458111).
I don't see how.

src/basic/escape.c
src/core/load-fragment.c

index 6095ac43b55b3ff09839a976b085d5ccc47340eb..9e75c51dfcbdbced21349f6fd2e6b62c4127b1b0 100644 (file)
@@ -355,6 +355,7 @@ ssize_t cunescape_length_with_prefix(const char *s, size_t length, const char *p
 
         *t = 0;
 
+        assert(t >= ans); /* Let static analyzers know that the answer is non-negative. */
         *ret = TAKE_PTR(ans);
         return t - *ret;
 }
index a3ac73f8232e54555380675d99c4c4a894afd84c..6eefaaf27d7700c28de9f2be5f4cf34419ee9077 100644 (file)
@@ -4513,7 +4513,7 @@ int config_parse_set_credential(
                         return 0;
                 }
         } else {
-                char *unescaped = NULL;
+                char *unescaped;
                 ssize_t l;
 
                 /* We support escape codes here, so that users can insert trailing \n if they like */