From c815acfb5863d9562a3f1e9cbd6204da3364860c Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Fri, 27 Mar 2015 12:02:49 +0100
Subject: [PATCH] fix gcc warnings about uninitialized variables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
like:
src/shared/install.c: In function ‘unit_file_lookup_state’:
src/shared/install.c:1861:16: warning: ‘r’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
return r < 0 ? r : state;
^
src/shared/install.c:1796:13: note: ‘r’ was declared here
int r;
^
Conflicts:
src/journal/journal-file.c
src/shared/btrfs-util.c
src/shared/install.c
Cherry-picked from: a7f7d1bde43fc825c49afea3f946f5b4b3d563e0
Related: #1318994
---
src/import/import-job.c | 2 +-
src/journal-remote/journal-gatewayd.c | 2 +-
src/journal-remote/journal-remote-parse.c | 2 +-
src/journal-remote/journal-remote.c | 4 ++--
src/journal/catalog.c | 2 +-
src/journal/coredump.c | 4 ++--
src/journal/journal-file.c | 6 +++---
src/journal/journal-vacuum.c | 2 +-
src/journal/journalctl.c | 2 +-
src/journal/test-journal-stream.c | 2 +-
src/libsystemd-network/lldp-tlv.c | 8 ++++----
src/libsystemd-network/sd-dhcp-server.c | 2 +-
src/libsystemd-network/sd-pppoe.c | 2 +-
src/libsystemd/sd-login/sd-login.c | 2 +-
src/network/networkctl.c | 2 +-
src/resolve/resolved-dns-transaction.c | 2 +-
src/resolve/test-dns-domain.c | 2 +-
src/shared/base-filesystem.c | 2 +-
src/shared/capability.c | 2 +-
src/shared/copy.c | 6 +++---
src/shared/install.c | 2 +-
src/shared/logs-show.c | 2 +-
src/shared/util.c | 4 ++--
src/test/test-path.c | 2 +-
src/test/test-pty.c | 2 +-
src/udev/net/link-config.c | 2 +-
26 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/src/import/import-job.c b/src/import/import-job.c
index 5f9cfd366..d826f493f 100644
--- a/src/import/import-job.c
+++ b/src/import/import-job.c
@@ -80,7 +80,7 @@ void import_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
long status;
int r;
- if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, &j) != CURLE_OK)
+ if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&j) != CURLE_OK)
return;
if (!j || j->state == IMPORT_JOB_DONE || j->state == IMPORT_JOB_FAILED)
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c
index 576f7cae7..d1f0ce3da 100644
--- a/src/journal-remote/journal-gatewayd.c
+++ b/src/journal-remote/journal-gatewayd.c
@@ -736,7 +736,7 @@ static int request_handler_machine(
RequestMeta *m = connection_cls;
int r;
_cleanup_free_ char* hostname = NULL, *os_name = NULL;
- uint64_t cutoff_from = 0, cutoff_to = 0, usage;
+ uint64_t cutoff_from = 0, cutoff_to = 0, usage = 0;
char *json;
sd_id128_t mid, bid;
_cleanup_free_ char *v = NULL;
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
index 7e6295435..64089da19 100644
--- a/src/journal-remote/journal-remote-parse.c
+++ b/src/journal-remote/journal-remote-parse.c
@@ -316,7 +316,7 @@ int process_data(RemoteSource *source) {
switch(source->state) {
case STATE_LINE: {
char *line, *sep;
- size_t n;
+ size_t n = 0;
assert(source->data_size == 0);
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index 9c515f9c8..4fac55cc9 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -353,7 +353,7 @@ static int remove_source(RemoteServer *s, int fd) {
static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
- RemoteSource *source;
+ RemoteSource *source = NULL;
int r;
/* This takes ownership of name, even on failure, if own_name is true. */
@@ -1148,7 +1148,7 @@ static int dispatch_raw_connection_event(sd_event_source *event,
.size = sizeof(union sockaddr_union),
.type = SOCK_STREAM,
};
- char *hostname;
+ char *hostname = NULL;
fd2 = accept_connection("raw", fd, &addr, &hostname);
if (fd2 < 0)
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index f17023284..a9c40c6d4 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -559,7 +559,7 @@ static const char *find_id(void *p, sd_id128_t id) {
int catalog_get(const char* database, sd_id128_t id, char **_text) {
_cleanup_close_ int fd = -1;
void *p = NULL;
- struct stat st;
+ struct stat st = {};
char *text = NULL;
int r;
const char *s;
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index f7ba0191e..59ccd46bb 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -244,7 +244,7 @@ static int maybe_remove_external_coredump(const char *filename, off_t size) {
static int make_filename(const char *info[_INFO_LEN], char **ret) {
_cleanup_free_ char *c = NULL, *u = NULL, *p = NULL, *t = NULL;
- sd_id128_t boot;
+ sd_id128_t boot = {};
int r;
assert(info);
@@ -843,7 +843,7 @@ log:
/* Optionally store the entire coredump in the journal */
if (IN_SET(arg_storage, COREDUMP_STORAGE_JOURNAL, COREDUMP_STORAGE_BOTH) &&
coredump_size <= (off_t) arg_journal_size_max) {
- size_t sz;
+ size_t sz = 0;
/* Store the coredump itself in the journal */
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index ef1849787..2a93460d4 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -911,7 +911,7 @@ int journal_file_find_data_object_with_hash(
if (o->object.flags & OBJECT_COMPRESSION_MASK) {
#if defined(HAVE_XZ) || defined(HAVE_LZ4)
uint64_t l;
- size_t rsize;
+ size_t rsize = 0;
l = le64toh(o->object.size);
if (l <= offsetof(Object, data.payload))
@@ -1075,7 +1075,7 @@ static int journal_file_append_data(
#if defined(HAVE_XZ) || defined(HAVE_LZ4)
if (JOURNAL_FILE_COMPRESS(f) && size >= COMPRESSION_SIZE_THRESHOLD) {
- size_t rsize;
+ size_t rsize = 0;
compression = compress_blob(data, size, o->data.payload, &rsize);
@@ -2903,7 +2903,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
if (o->object.flags & OBJECT_COMPRESSION_MASK) {
#if defined(HAVE_XZ) || defined(HAVE_LZ4)
- size_t rsize;
+ size_t rsize = 0;
r = decompress_blob(o->object.flags & OBJECT_COMPRESSION_MASK,
o->data.payload, l, &from->compress_buffer, &from->compress_buffer_size, &rsize, 0);
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index 832c327b3..856d11e4e 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -76,7 +76,7 @@ static void patch_realtime(
unsigned long long *realtime) {
_cleanup_free_ const char *path = NULL;
- usec_t x, crtime;
+ usec_t x, crtime = 0;
/* The timestamp was determined by the file name, but let's
* see if the file might actually be older than the file name
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index a38ce4b8f..6ba884779 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1644,7 +1644,7 @@ static int verify(sd_journal *j) {
ORDERED_HASHMAP_FOREACH(f, j->files, i) {
int k;
- usec_t first, validated, last;
+ usec_t first = 0, validated = 0, last = 0;
#ifdef HAVE_GCRYPT
if (!arg_verify_key && JOURNAL_HEADER_SEALED(f->header))
diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c
index 3996e778e..b8caeb3d4 100644
--- a/src/journal/test-journal-stream.c
+++ b/src/journal/test-journal-stream.c
@@ -42,7 +42,7 @@ static void verify_contents(sd_journal *j, unsigned skip) {
const void *d;
char *k, *c;
size_t l;
- unsigned u;
+ unsigned u = 0;
assert_se(sd_journal_get_cursor(j, &k) >= 0);
printf("cursor: %s\n", k);
diff --git a/src/libsystemd-network/lldp-tlv.c b/src/libsystemd-network/lldp-tlv.c
index e43d70d3c..e32783f3e 100644
--- a/src/libsystemd-network/lldp-tlv.c
+++ b/src/libsystemd-network/lldp-tlv.c
@@ -156,7 +156,7 @@ static inline int tlv_packet_read_internal(tlv_section *m, void **data) {
}
int tlv_packet_read_u8(tlv_packet *m, uint8_t *data) {
- void *val;
+ void *val = NULL;
int r;
assert_return(m, -EINVAL);
@@ -174,7 +174,7 @@ int tlv_packet_read_u8(tlv_packet *m, uint8_t *data) {
int tlv_packet_read_u16(tlv_packet *m, uint16_t *data) {
uint16_t t;
- void *val;
+ void *val = NULL;
int r;
assert_return(m, -EINVAL);
@@ -211,7 +211,7 @@ int tlv_packet_read_u32(tlv_packet *m, uint32_t *data) {
}
int tlv_packet_read_string(tlv_packet *m, char **data, uint16_t *data_length) {
- void *val;
+ void *val = NULL;
int r;
assert_return(m, -EINVAL);
@@ -229,7 +229,7 @@ int tlv_packet_read_string(tlv_packet *m, char **data, uint16_t *data_length) {
}
int tlv_packet_read_bytes(tlv_packet *m, uint8_t **data, uint16_t *data_length) {
- void *val;
+ void *val = NULL;
int r;
assert_return(m, -EINVAL);
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 3f89f344d..0f284eb6a 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -776,7 +776,7 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
if (pool_offset >= 0 &&
server->bound_leases[pool_offset] == existing_lease) {
DHCPLease *lease;
- usec_t time_now;
+ usec_t time_now = 0;
if (!existing_lease) {
lease = new0(DHCPLease, 1);
diff --git a/src/libsystemd-network/sd-pppoe.c b/src/libsystemd-network/sd-pppoe.c
index 4f49b799e..83e58a3db 100644
--- a/src/libsystemd-network/sd-pppoe.c
+++ b/src/libsystemd-network/sd-pppoe.c
@@ -340,7 +340,7 @@ static int pppoe_timeout(sd_event_source *s, uint64_t usec, void *userdata);
static int pppoe_arm_timeout(sd_pppoe *ppp) {
_cleanup_event_source_unref_ sd_event_source *timeout = NULL;
- usec_t next_timeout;
+ usec_t next_timeout = 0;
int r;
assert(ppp);
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index f71749f72..cc0677bdf 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -82,7 +82,7 @@ _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
}
_public_ int sd_peer_get_session(int fd, char **session) {
- struct ucred ucred;
+ struct ucred ucred = {};
int r;
assert_return(fd >= 0, -EINVAL);
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index aa83f32f5..778670b73 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -964,7 +964,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
return -ENOMEM;
} else if (streq(a, "_TTL")) {
- long long unsigned x;
+ long long unsigned x = 0;
usec_t time;
r = safe_atollu(b, &x);
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 74b063414..bc1a90db1 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -252,7 +252,7 @@ static int dns_transaction_open_tcp(DnsTransaction *t) {
fd = dns_scope_tcp_socket(t->scope, t->received->family, &t->received->sender, t->received->sender_port);
else {
union in_addr_union address;
- int family;
+ int family = AF_UNSPEC;
/* Otherwise, try to talk to the owner of a
* the IP address, in case this is a reverse
diff --git a/src/resolve/test-dns-domain.c b/src/resolve/test-dns-domain.c
index ebc8d98fc..4963a9c6a 100644
--- a/src/resolve/test-dns-domain.c
+++ b/src/resolve/test-dns-domain.c
@@ -162,7 +162,7 @@ static void test_dns_name_single_label(void) {
static void test_dns_name_reverse_one(const char *address, const char *name) {
_cleanup_free_ char *p = NULL;
- union in_addr_union a, b;
+ union in_addr_union a, b = {};
int familya, familyb;
assert_se(in_addr_from_string_auto(address, &familya, &a) >= 0);
diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c
index 73907c635..20a69bdbf 100644
--- a/src/shared/base-filesystem.c
+++ b/src/shared/base-filesystem.c
@@ -55,7 +55,7 @@ static const BaseFilesystem table[] = {
int base_filesystem_create(const char *root) {
_cleanup_close_ int fd = -1;
unsigned i;
- int r;
+ int r = 0;
fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (fd < 0)
diff --git a/src/shared/capability.c b/src/shared/capability.c
index 915ceb9d9..2b963fde3 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -55,7 +55,7 @@ unsigned long cap_last_cap(void) {
static thread_local unsigned long saved;
static thread_local bool valid = false;
_cleanup_free_ char *content = NULL;
- unsigned long p;
+ unsigned long p = 0;
int r;
if (valid)
diff --git a/src/shared/copy.c b/src/shared/copy.c
index 0239a5806..2a0cb2808 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -360,7 +360,7 @@ int copy_file_fd(const char *from, int fdt, bool try_reflink) {
}
int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags) {
- int fdt, r;
+ int fdt = -1, r;
assert(from);
assert(to);
@@ -390,7 +390,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned
}
int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags) {
- _cleanup_free_ char *t;
+ _cleanup_free_ char *t = NULL;
int r;
assert(from);
@@ -415,7 +415,7 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace
int copy_times(int fdf, int fdt) {
struct timespec ut[2];
struct stat st;
- usec_t crtime;
+ usec_t crtime = 0;
assert(fdf >= 0);
assert(fdt >= 0);
diff --git a/src/shared/install.c b/src/shared/install.c
index 9962508b1..61aaafe7b 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -2046,7 +2046,7 @@ UnitFileState unit_file_lookup_state(
_cleanup_(install_context_done) InstallContext c = {};
InstallInfo *i;
UnitFileState state;
- int r;
+ int r = 0;
assert(paths);
assert(name);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 8c374116a..a572be94b 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -993,7 +993,7 @@ static int show_journal(FILE *f,
if (warn_cutoff && line < how_many && not_before > 0) {
sd_id128_t boot_id;
- usec_t cutoff;
+ usec_t cutoff = 0;
/* Check whether the cutoff line is too early */
diff --git a/src/shared/util.c b/src/shared/util.c
index 303026152..4c441a544 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3073,7 +3073,7 @@ int getttyname_malloc(int fd, char **ret) {
int getttyname_harder(int fd, char **r) {
int k;
- char *s;
+ char *s = NULL;
k = getttyname_malloc(fd, &s);
if (k < 0)
@@ -3627,7 +3627,7 @@ char **replace_env_argv(char **argv, char **env) {
/* If $FOO appears as single word, replace it by the split up variable */
if ((*i)[0] == '$' && (*i)[1] != '{') {
char *e;
- char **w, **m;
+ char **w, **m = NULL;
unsigned q;
e = strv_env_get(env, *i+1);
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 4f9f5c134..a3295aa99 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -33,7 +33,7 @@ static int setup_test(Manager **m) {
char **tests_path = STRV_MAKE("exists", "existsglobFOOBAR", "changed", "modified", "unit",
"directorynotempty", "makedirectory");
char **test_path;
- Manager *tmp;
+ Manager *tmp = NULL;
int r;
assert_se(m);
diff --git a/src/test/test-pty.c b/src/test/test-pty.c
index cab569a9d..67c125a4c 100644
--- a/src/test/test-pty.c
+++ b/src/test/test-pty.c
@@ -97,7 +97,7 @@ static void run_parent(Pty *pty) {
static void test_pty(void) {
pid_t pid;
- Pty *pty;
+ Pty *pty = NULL;
rcvsiz = 0;
zero(rcvbuf);
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 489593f4f..ad6a82e50 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -474,7 +474,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
int link_get_driver(link_config_ctx *ctx, struct udev_device *device, char **ret) {
const char *name;
- char *driver;
+ char *driver = NULL;
int r;
name = udev_device_get_sysname(device);