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;
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;
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);
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;
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));
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)
}
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);
}
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);
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,
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);
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);
"/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) : "-");
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);
}
{
- _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);
}
{
- _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);
}
{
- _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);
/* /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);
}
{
- _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);
}
{
- _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);
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);
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);
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;
(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));
}
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));
}
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));
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;
}
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));
}
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));
}
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);
}
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);
}
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);
#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"));
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));
}
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);
}
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);
}
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);
}
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);
*/
static int run(int argc, char **argv) {
- _cleanup_close_ int fd;
+ _cleanup_close_ int fd = -EBADF;
char **args = strv_skip(argv, 1);
int r;
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);
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);
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);
}
}
} 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));
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], ", ");
}
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();
}
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);
}
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;
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));
}
}
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);
}
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);
}
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);
"\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);
#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"));
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);