]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Fix false positives on newer gcc
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 23 May 2023 11:25:58 +0000 (13:25 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 23 May 2023 18:45:27 +0000 (19:45 +0100)
Recent gcc versions have started to trigger false positive
maybe-uninitialized warnings. Let's make sure we initialize
variables annotated with _cleanup_ to avoid these.

26 files changed:
src/home/homework-luks.c
src/journal/test-journal-interleaving.c
src/libsystemd-network/test-dhcp-client.c
src/libsystemd/sd-device/test-sd-device.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-journal/test-catalog.c
src/libudev/test-libudev.c
src/resolve/test-resolved-etc-hosts.c
src/test/test-bpf-devices.c
src/test/test-compress-benchmark.c
src/test/test-copy.c
src/test/test-date.c
src/test/test-ellipsize.c
src/test/test-escape.c
src/test/test-execve.c
src/test/test-fileio.c
src/test/test-json.c
src/test/test-nss-hosts.c
src/test/test-sleep.c
src/test/test-strbuf.c
src/test/test-string-util.c
src/test/test-strv.c
src/test/test-time-util.c
src/test/test-unit-name.c
src/test/test-utf8.c
src/xdg-autostart-generator/test-xdg-autostart.c

index 802d9bf6f95662044e805485f3656b867a291e75..e1f0ff1dcbef05862ddde0d711ca480ea936ce52 100644 (file)
@@ -1230,7 +1230,7 @@ int home_setup_luks(
                 PasswordCache *cache,
                 UserRecord **ret_luks_home) {
 
-        sd_id128_t found_partition_uuid, found_fs_uuid, found_luks_uuid = SD_ID128_NULL;
+        sd_id128_t found_partition_uuid, found_fs_uuid = SD_ID128_NULL, found_luks_uuid = SD_ID128_NULL;
         _cleanup_(user_record_unrefp) UserRecord *luks_home = NULL;
         _cleanup_(erase_and_freep) void *volume_key = NULL;
         size_t volume_key_size = 0;
index 308569d786d220c58dc3a56ed019eb0085db00e2..97cca9bf6a514aebd36b50ee2d28dc394f481824 100644 (file)
@@ -72,7 +72,7 @@ static void append_number(ManagedJournalFile *f, int n, uint64_t *seqnum) {
 
 static void test_check_number(sd_journal *j, int n) {
         const void *d;
-        _cleanup_free_ char *k;
+        _cleanup_free_ char *k = NULL;
         size_t l;
         int x;
 
index e4354199e10b49851a7bf6408cd6e1711426bb9a..f3f558a358513edb01f89e30f53fe30adcf0eecb 100644 (file)
@@ -189,7 +189,7 @@ static int check_options(uint8_t code, uint8_t len, const void *option, void *us
 
 int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link, const void *packet, size_t len) {
         size_t size;
-        _cleanup_free_ DHCPPacket *discover;
+        _cleanup_free_ DHCPPacket *discover = NULL;
         uint16_t ip_check, udp_check;
 
         assert_se(s >= 0);
index 9d5cab75b3a1e77ebc9923c219bb3dca77d68150..8c6d59e0409d3d231b6f2a90a22e13beb2c37273 100644 (file)
@@ -266,7 +266,7 @@ static void test_sd_device_enumerator_filter_subsystem_one(
 
 static bool test_sd_device_enumerator_filter_subsystem_trial(void) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
-        _cleanup_(hashmap_freep) Hashmap *subsystems;
+        _cleanup_(hashmap_freep) Hashmap *subsystems = NULL;
         unsigned n_new_dev = 0, n_removed_dev = 0;
         sd_device *d;
         Hashmap *h;
index 4f61af50f339ef046ad4eac9ee926f3bc97e047b..7892f2bc2e3a5b0cf20afcf5474e0906eb81f95a 100644 (file)
@@ -506,7 +506,7 @@ static void test_inotify_one(unsigned n_create_events) {
 
         for (i = 0; i < n_create_events; i++) {
                 char buf[DECIMAL_STR_MAX(unsigned)+1];
-                _cleanup_free_ char *z;
+                _cleanup_free_ char *z = NULL;
 
                 xsprintf(buf, "%u", i);
                 assert_se(z = path_join(p, buf));
index 49185cc2b32e7967116fa94e14e3e7aaa4007fa9..603952e904a5a65f0520028544afe586a0c53c78 100644 (file)
@@ -27,7 +27,7 @@ static const char *no_catalog_dirs[] = {
 
 static OrderedHashmap* test_import(const char* contents, ssize_t size, int code) {
         _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-catalog.XXXXXX";
-        _cleanup_close_ int fd;
+        _cleanup_close_ int fd = -EBADF;
         OrderedHashmap *h;
 
         if (size < 0)
index 94d34b1ae2e552171577221b2b0fb260ad6a867b..839a6a1a742dada69ca3446ff6b277f414c8e804 100644 (file)
@@ -91,7 +91,7 @@ static void print_device(struct udev_device *device) {
 }
 
 static void test_device(struct udev *udev, const char *syspath) {
-        _cleanup_(udev_device_unrefp) struct udev_device *device;
+        _cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
 
         log_info("/* %s, device %s */", __func__, syspath);
         device = udev_device_new_from_syspath(udev, syspath);
@@ -102,7 +102,7 @@ static void test_device(struct udev *udev, const char *syspath) {
 }
 
 static void test_device_parents(struct udev *udev, const char *syspath) {
-        _cleanup_(udev_device_unrefp) struct udev_device *device;
+        _cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
         struct udev_device *device_parent;
 
         log_info("/* %s, device %s */", __func__, syspath);
@@ -172,7 +172,7 @@ static int enumerate_print_list(struct udev_enumerate *enumerate) {
 
 static void test_monitor(struct udev *udev) {
         _cleanup_(udev_monitor_unrefp) struct udev_monitor *udev_monitor;
-        _cleanup_close_ int fd_ep;
+        _cleanup_close_ int fd_ep = -EBADF;
         int fd_udev;
         struct epoll_event ep_udev = {
                 .events = EPOLLIN,
index 19b2991a356ae26ec00b2c07ed40d2ee1332a21f..d46dbd30009d5dc831946ef94c46c7af6b9d7e9b 100644 (file)
@@ -38,7 +38,7 @@ TEST(parse_etc_hosts) {
                 t[] = "/tmp/test-resolved-etc-hosts.XXXXXX";
 
         int fd;
-        _cleanup_fclose_ FILE *f;
+        _cleanup_fclose_ FILE *f = NULL;
 
         fd = mkostemp_safe(t);
         assert_se(fd >= 0);
@@ -118,7 +118,7 @@ TEST(parse_etc_hosts) {
 
 static void test_parse_file_one(const char *fname) {
         _cleanup_(etc_hosts_clear) EtcHosts hosts = {};
-        _cleanup_fclose_ FILE *f;
+        _cleanup_fclose_ FILE *f = NULL;
 
         log_info("/* %s(\"%s\") */", __func__, fname);
 
index e17548373413ae19869897d135601d0a6cc7acaa..0e1287eac4ea0e37c61d5b0d7f75cb0ad2dd162e 100644 (file)
@@ -37,7 +37,7 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
                           "/dev/urandom",
                           "/dev/tty",
                           "/dev/ptmx") {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
                 log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
@@ -74,7 +74,7 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
         assert_se(r >= 0);
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -87,7 +87,7 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
         }
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/random";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -100,7 +100,7 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
         }
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/zero";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -113,7 +113,7 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
         }
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/full";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -146,7 +146,7 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
 
         /* /dev/null, /dev/full have major==1, /dev/tty has major==5 */
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -159,7 +159,7 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
         }
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/full";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -172,7 +172,7 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
         }
 
         {
-                _cleanup_close_ int fd, fd2;
+                _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
                 const char *s = "/dev/tty";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
@@ -204,7 +204,7 @@ static void test_policy_allow_list_major_star(char type, const char *cgroup_path
         assert_se(r >= 0);
 
         {
-                _cleanup_close_ int fd;
+                _cleanup_close_ int fd = -EBADF;
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDWR|O_NOCTTY);
@@ -237,7 +237,7 @@ static void test_policy_empty(bool add_mismatched, const char *cgroup_path, BPFP
         assert_se(r >= 0);
 
         {
-                _cleanup_close_ int fd;
+                _cleanup_close_ int fd = -EBADF;
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDWR|O_NOCTTY);
index 6180e19839ff0f8d402ac750c1624a77f111ebef..1727db8134d1b1dea4f37fe121f725509e586e31 100644 (file)
@@ -78,7 +78,7 @@ static void test_compress_decompress(const char* label, const char* type,
         usec_t n, n2 = 0;
         float dt;
 
-        _cleanup_free_ char *text, *buf;
+        _cleanup_free_ char *text = NULL, *buf = NULL;
         _cleanup_free_ void *buf2 = NULL;
         size_t skipped = 0, compressed = 0, total = 0;
 
index 38855fd45e07411e5d7d2af96b177b75b03069e8..f5bcb8756f9d09e18627279c30494798d0c036f6 100644 (file)
@@ -144,7 +144,7 @@ TEST(copy_tree) {
         (void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
 
         STRV_FOREACH(p, files) {
-                _cleanup_free_ char *f, *c;
+                _cleanup_free_ char *f = NULL, *c = NULL;
                 int k;
 
                 assert_se(f = path_join(original_dir, *p));
@@ -159,7 +159,7 @@ TEST(copy_tree) {
         }
 
         STRV_FOREACH_PAIR(ll, p, symlinks) {
-                _cleanup_free_ char *f, *l;
+                _cleanup_free_ char *f = NULL, *l = NULL;
 
                 assert_se(f = path_join(original_dir, *p));
                 assert_se(l = path_join(original_dir, *ll));
@@ -169,7 +169,7 @@ TEST(copy_tree) {
         }
 
         STRV_FOREACH_PAIR(ll, p, hardlinks) {
-                _cleanup_free_ char *f, *l;
+                _cleanup_free_ char *f = NULL, *l = NULL;
 
                 assert_se(f = path_join(original_dir, *p));
                 assert_se(l = path_join(original_dir, *ll));
@@ -191,7 +191,7 @@ TEST(copy_tree) {
         assert_se(copy_tree(original_dir, copy_dir, UID_INVALID, GID_INVALID, COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS, denylist) == 0);
 
         STRV_FOREACH(p, files) {
-                _cleanup_free_ char *buf, *f, *c = NULL;
+                _cleanup_free_ char *buf = NULL, *f = NULL, *c = NULL;
                 size_t sz;
                 int k;
 
@@ -213,7 +213,7 @@ TEST(copy_tree) {
         }
 
         STRV_FOREACH_PAIR(ll, p, symlinks) {
-                _cleanup_free_ char *target, *f, *l;
+                _cleanup_free_ char *target = NULL, *f = NULL, *l = NULL;
 
                 assert_se(f = strjoin(original_dir, *p));
                 assert_se(l = strjoin(copy_dir, *ll));
@@ -223,7 +223,7 @@ TEST(copy_tree) {
         }
 
         STRV_FOREACH_PAIR(ll, p, hardlinks) {
-                _cleanup_free_ char *f, *l;
+                _cleanup_free_ char *f = NULL, *l = NULL;
                 struct stat a, b;
 
                 assert_se(f = strjoin(copy_dir, *p));
index 16c6d4e5be2bf266b303801d50b40474f5155b5a..a7058a33d4241de3704bd15f51579cc5bb70dea2 100644 (file)
@@ -46,7 +46,7 @@ static void test_should_fail(const char *p) {
 }
 
 static void test_one(const char *p) {
-        _cleanup_free_ char *with_utc;
+        _cleanup_free_ char *with_utc = NULL;
 
         with_utc = strjoin(p, " UTC");
         test_should_pass(p);
@@ -54,7 +54,7 @@ static void test_one(const char *p) {
 }
 
 static void test_one_noutc(const char *p) {
-        _cleanup_free_ char *with_utc;
+        _cleanup_free_ char *with_utc = NULL;
 
         with_utc = strjoin(p, " UTC");
         test_should_pass(p);
index 2b27b44efb1ae5d14c8e23cb24aabf51079d645e..a96644f6176d88e87059fe688d91eb370e22bdea 100644 (file)
@@ -75,7 +75,7 @@ TEST(ellipsize_mem) {
 }
 
 static void test_ellipsize_one(const char *p) {
-        _cleanup_free_ char *t;
+        _cleanup_free_ char *t = NULL;
         t = ellipsize(p, columns(), 70);
         puts(t);
         free(t);
index f3dd579e56d4813e547d678eae3101045dfd3fc2..f74f4f590d15fbdc8b80cd888096d5dc44235a35 100644 (file)
@@ -6,14 +6,14 @@
 #include "tests.h"
 
 TEST(cescape) {
-        _cleanup_free_ char *t;
+        _cleanup_free_ char *t = NULL;
 
         assert_se(t = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
         assert_se(streq(t, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
 }
 
 TEST(xescape) {
-        _cleanup_free_ char *t;
+        _cleanup_free_ char *t = NULL;
 
         assert_se(t = xescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", ""));
         assert_se(streq(t, "abc\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\\x7f\\x9c\\xcb"));
@@ -29,7 +29,7 @@ static void test_xescape_full_one(bool eight_bits) {
         log_info("/* %s */", __func__);
 
         for (unsigned i = 0; i < 60; i++) {
-                _cleanup_free_ char *t, *q;
+                _cleanup_free_ char *t = NULL, *q = NULL;
 
                 assert_se(t = xescape_full("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", "b", i, flags));
 
@@ -65,7 +65,7 @@ TEST(test_xescape_full) {
 }
 
 TEST(cunescape) {
-        _cleanup_free_ char *unescaped;
+        _cleanup_free_ char *unescaped = NULL;
 
         assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", 0, &unescaped) < 0);
         assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", UNESCAPE_RELAX, &unescaped) >= 0);
@@ -132,7 +132,7 @@ TEST(cunescape) {
 }
 
 static void test_shell_escape_one(const char *s, const char *bad, const char *expected) {
-        _cleanup_free_ char *r;
+        _cleanup_free_ char *r = NULL;
 
         assert_se(r = shell_escape(s, bad));
         log_debug("%s → %s (expected %s)", s, r, expected);
@@ -203,7 +203,7 @@ TEST(shell_maybe_quote) {
 }
 
 static void test_quote_command_line_one(char **argv, const char *expected) {
-        _cleanup_free_ char *s;
+        _cleanup_free_ char *s = NULL;
 
         assert_se(s = quote_command_line(argv, SHELL_ESCAPE_EMPTY));
         log_info("%s", s);
@@ -224,7 +224,7 @@ TEST(quote_command_line) {
 }
 
 static void test_octescape_one(const char *s, const char *expected) {
-        _cleanup_free_ char *ret;
+        _cleanup_free_ char *ret = NULL;
 
         assert_se(ret = octescape(s, strlen_ptr(s)));
         log_debug("octescape(\"%s\") → \"%s\" (expected: \"%s\")", strnull(s), ret, expected);
index 38adc728adf620f274187ca519c2488d86c0f75c..e7a9a5137741310be6692d75f5a801905a03ee8c 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 static int run(int argc, char **argv) {
-        _cleanup_close_ int fd;
+        _cleanup_close_ int fd = -EBADF;
         char **args = strv_skip(argv, 1);
         int r;
 
index a570941cf303fe6dd937908c4345c40a86d62f50..aa5142fcedf5469f8f03d943cd330779446b4ec0 100644 (file)
@@ -460,7 +460,7 @@ TEST(write_string_stream) {
 TEST(write_string_file) {
         _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file-XXXXXX";
         char buf[64] = {};
-        _cleanup_close_ int fd;
+        _cleanup_close_ int fd = -EBADF;
 
         fd = mkostemp_safe(fn);
         assert_se(fd >= 0);
@@ -473,7 +473,7 @@ TEST(write_string_file) {
 
 TEST(write_string_file_no_create) {
         _cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX";
-        _cleanup_close_ int fd;
+        _cleanup_close_ int fd = -EBADF;
         char buf[64] = {};
 
         fd = mkostemp_safe(fn);
index 0f5c5b1a6e87e48248a12e16149ebffd4970c9e7..6a544c3fb7ba9ea23bb17f74f4158de9b4013148 100644 (file)
@@ -18,7 +18,7 @@ static void test_tokenizer_one(const char *data, ...) {
         void *state = NULL;
         va_list ap;
 
-        _cleanup_free_ char *cdata;
+        _cleanup_free_ char *cdata = NULL;
         assert_se(cdata = cescape(data));
         log_info("/* %s data=\"%s\" */", __func__, cdata);
 
index 2fbcde41d6b489e038c967bee4d7e4ce80bda54b..7758f0adc988b5ab267f176f7282f37edc740a9e 100644 (file)
@@ -449,7 +449,7 @@ static int parse_argv(int argc, char **argv,
                         }
                 }
         } else {
-                _cleanup_free_ char *hostname;
+                _cleanup_free_ char *hostname = NULL;
                 assert_se(hostname = gethostname_malloc());
                 assert_se(names = strv_new("localhost", "_gateway", "_outbound", "foo_no_such_host", hostname));
 
index 558907600575df66f2615efa56edf90d832b3a49..a873e6eb1bc57b4982e5e06d1c12b3ca49e9129f 100644 (file)
@@ -21,7 +21,7 @@ TEST(parse_sleep_config) {
 
         assert_se(parse_sleep_config(&sleep_config) == 0);
 
-        _cleanup_free_ char *sum, *sus, *him, *his, *hym, *hys;
+        _cleanup_free_ char *sum = NULL, *sus = NULL, *him = NULL, *his = NULL, *hym = NULL, *hys = NULL;
 
         sum = strv_join(sleep_config->modes[SLEEP_SUSPEND], ", ");
         sus = strv_join(sleep_config->states[SLEEP_SUSPEND], ", ");
index f69e80ca5a84911b65342722c408b589c24fb0e3..39a7142b5bb645a7af65cdd649c14a6c2ea6bf80 100644 (file)
@@ -13,8 +13,8 @@ static ssize_t add_string(struct strbuf *sb, const char *s) {
 }
 
 TEST(strbuf) {
-        _cleanup_(strbuf_freep) struct strbuf *sb;
-        _cleanup_strv_free_ char **l;
+        _cleanup_(strbuf_freep) struct strbuf *sb = NULL;
+        _cleanup_strv_free_ char **l = NULL;
         ssize_t a, b, c, d, e, f, g, h;
 
         sb = strbuf_new();
index 65052c627d7c397fdbe4c3b4f65931ba76661f14..2d3e40321e52249330c7533fb1da62e03d7d2db8 100644 (file)
@@ -259,7 +259,7 @@ TEST(strextend_with_separator) {
 }
 
 TEST(strrep) {
-        _cleanup_free_ char *one, *three, *zero;
+        _cleanup_free_ char *one = NULL, *three = NULL, *zero = NULL;
         one = strrep("waldo", 1);
         three = strrep("waldo", 3);
         zero = strrep("waldo", 0);
index a39a2d812203f52dd268c7fbd4df496928b65f86..5feafc95e0184522865c023442c7794007766eb3 100644 (file)
@@ -200,8 +200,8 @@ TEST(strv_join_full) {
 }
 
 static void test_strv_unquote_one(const char *quoted, char **list) {
-        _cleanup_strv_free_ char **s;
-        _cleanup_free_ char *j;
+        _cleanup_strv_free_ char **s = NULL;
+        _cleanup_free_ char *j = NULL;
         unsigned i = 0;
         int r;
 
index 42701618048765e6a65760085cfc88d5960556dc..e80922901e0f8347a4a2e3f02ea4e75fbbb23018 100644 (file)
@@ -244,7 +244,7 @@ TEST(format_timespan) {
         test_format_timespan_accuracy(USEC_PER_SEC);
 
         /* See issue #23928. */
-        _cleanup_free_ char *buf;
+        _cleanup_free_ char *buf = NULL;
         assert_se(buf = new(char, 5));
         assert_se(buf == format_timespan(buf, 5, 100005, 1000));
 }
index ed3f2dfc7866b0a6eea07aa2e4c430c999a6723a..ada8330408c47cbc9cfa04aa95c34bb066b4c0fd 100644 (file)
@@ -583,7 +583,7 @@ TEST(unit_name_to_instance) {
 }
 
 TEST(unit_name_escape) {
-        _cleanup_free_ char *r;
+        _cleanup_free_ char *r = NULL;
 
         r = unit_name_escape("ab+-c.a/bc@foo.service");
         assert_se(r);
index 7ba0cb7dd233b6d8349b83d2baf292732b6c0885..1b7da9d511e0e6bec4bee2952878abdf86cb5778 100644 (file)
@@ -99,7 +99,7 @@ TEST(utf8_encoded_valid_unichar) {
 }
 
 TEST(utf8_escape_invalid) {
-        _cleanup_free_ char *p1, *p2, *p3;
+        _cleanup_free_ char *p1 = NULL, *p2 = NULL, *p3 = NULL;
 
         p1 = utf8_escape_invalid("goo goo goo");
         log_debug("\"%s\"", p1);
@@ -115,7 +115,7 @@ TEST(utf8_escape_invalid) {
 }
 
 TEST(utf8_escape_non_printable) {
-        _cleanup_free_ char *p1, *p2, *p3, *p4, *p5, *p6;
+        _cleanup_free_ char *p1 = NULL, *p2 = NULL, *p3 = NULL, *p4 = NULL, *p5 = NULL, *p6 = NULL;
 
         p1 = utf8_escape_non_printable("goo goo goo");
         log_debug("\"%s\"", p1);
@@ -148,7 +148,7 @@ TEST(utf8_escape_non_printable_full) {
                        "\001 \019\20\a",    /* control characters */
                        "\xef\xbf\x30\x13")  /* misplaced continuation bytes followed by a digit and cc */
                 for (size_t cw = 0; cw < 22; cw++) {
-                        _cleanup_free_ char *p, *q;
+                        _cleanup_free_ char *p = NULL, *q = NULL;
                         size_t ew;
 
                         p = utf8_escape_non_printable_full(s, cw, false);
index e11f3d9385d1c4f08c715a9827f0691b9b40cd09..81f85d6b1563a873709cb7da55a40b4c06300d6f 100644 (file)
@@ -10,7 +10,7 @@
 #include "xdg-autostart-service.h"
 
 TEST(translate_name) {
-        _cleanup_free_ char *t;
+        _cleanup_free_ char *t = NULL;
 
         assert_se(t = xdg_autostart_service_translate_name("a-b.blub.desktop"));
         assert_se(streq(t, "app-a\\x2db.blub@autostart.service"));
@@ -26,7 +26,7 @@ static void test_xdg_format_exec_start_one(const char *exec, const char *expecte
 
 TEST(xdg_format_exec_start) {
         _cleanup_free_ char *home = NULL;
-        _cleanup_free_ char *expected1, *expected2 = NULL;
+        _cleanup_free_ char *expected1 = NULL, *expected2 = NULL;
 
         assert_se(get_home_dir(&home) >= 0);