]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fix gcc warnings about uninitialized variables
authorHarald Hoyer <harald@redhat.com>
Fri, 27 Mar 2015 11:02:49 +0000 (12:02 +0100)
committerHarald Hoyer <harald@redhat.com>
Fri, 27 Mar 2015 13:57:38 +0000 (14:57 +0100)
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;
             ^

27 files changed:
src/import/pull-job.c
src/journal-remote/journal-gatewayd.c
src/journal-remote/journal-remote-parse.c
src/journal-remote/journal-remote.c
src/journal/catalog.c
src/journal/coredump.c
src/journal/journal-file.c
src/journal/journal-vacuum.c
src/journal/journalctl.c
src/journal/test-journal-stream.c
src/libsystemd-network/lldp-tlv.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd-network/sd-pppoe.c
src/libsystemd/sd-login/sd-login.c
src/network/networkctl.c
src/resolve/resolved-dns-transaction.c
src/resolve/test-dns-domain.c
src/shared/base-filesystem.c
src/shared/btrfs-util.c
src/shared/capability.c
src/shared/copy.c
src/shared/install.c
src/shared/logs-show.c
src/shared/util.c
src/test/test-path.c
src/test/test-pty.c
src/udev/net/link-config.c

index ed9af2351ffe4ffe5ab16f8aab808094731b9a71..42939f21045d66c3d19829cfa130fba48e1c81e3 100644 (file)
@@ -76,7 +76,7 @@ void pull_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 == PULL_JOB_DONE || j->state == PULL_JOB_FAILED)
index 6efc9b385fc8744089b36b848533602750234309..bba0d12ee78000af5fee8f8ff34dc05901deb71f 100644 (file)
@@ -748,7 +748,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;
index e8442d319e584ba27f541e09dad496a25268bfae..5ff05d3ad6182661f95c21b3a297af9eff00d5cf 100644 (file)
@@ -321,7 +321,7 @@ static 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);
 
index 6198a99b75bfea009d4dd66537445c4e1b8e5ce4..f87a939168fe51a98ba0da35c4910c32cf48866d 100644 (file)
@@ -349,7 +349,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. */
@@ -1144,7 +1144,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)
index e505a05305fe241e49069e7e99b31a312ddf4f10..0801e135990c10c2fb51189043448f01c79c520f 100644 (file)
@@ -558,7 +558,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;
index 6357d3e277295b3fde0f95ea24f9984cd386c152..4e23e487fbbe55d735f22f8a5173ec261edab350 100644 (file)
@@ -242,7 +242,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);
@@ -841,7 +841,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 */
 
index 8e7642710e71b313b65bcdf2db5d9af5cb3a116e..5a4e7cbd7daee68d5302819b4f114c290128545c 100644 (file)
@@ -887,7 +887,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))
@@ -1052,7 +1052,7 @@ static int journal_file_append_data(
 #if defined(HAVE_XZ) || defined(HAVE_LZ4)
         if (f->compress_xz &&
             size >= COMPRESSION_SIZE_THRESHOLD) {
-                size_t rsize;
+                size_t rsize = 0;
 
                 compression = compress_blob(data, size, o->data.payload, &rsize);
 
@@ -2886,7 +2886,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);
index a367dc1bb9e2d30877af8c751784f287503165e5..81a577ea276f2a59bac2265f52536faf3ea7969c 100644 (file)
@@ -73,7 +73,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
index 7fbd518d3ffcefef36b095ffd506252e75dc886d..b4f88bcd0aa10d3bed1c63c9949a1e0682ccf702 100644 (file)
@@ -1487,7 +1487,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))
index 3996e778e666d43e6bbb79cad77541087fccaec2..b8caeb3d41f0cfab5da6f678307eac26b3088bef 100644 (file)
@@ -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);
index e43d70d3cfe0eb1ef4625e460e0bfd0b8749d542..e32783f3ebab83b7310a407bc550610f9a2360ee 100644 (file)
@@ -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);
index 2634a730d65552fa96f7c009246664d71f19f1dd..a0a2320efa4736c17f83b8b61a9d9d5ae6a6c792 100644 (file)
@@ -775,7 +775,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);
index e8e7d994df2a174df40ff70ba6ce85f04f92919f..601f3bd400a84961a5a66311c5f445275e152461 100644 (file)
@@ -339,7 +339,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);
index f71749f72d4d136c15a480cf218764986551abf4..cc0677bdf21c94a72e9ea36d1ac76aebd699f6f4 100644 (file)
@@ -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);
index 3a6faa273d14c4012ba090aa5db04a65041c18de..46653189fb0ed0d566e9ff42800b40d9d5582ae0 100644 (file)
@@ -975,7 +975,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                                                 return r;
 
                                 } else if (streq(a, "_TTL")) {
-                                        long long unsigned x;
+                                        long long unsigned x = 0;
                                         usec_t time;
 
                                         r = safe_atollu(b, &x);
index 74b0634142be5fbd9fd141969402c27ac44617be..bc1a90db1bb22ebdabf1316e71df6502743237b3 100644 (file)
@@ -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
index 2f3edaf783d6443e8d8bda3d86971719b644a0a4..c3208abc7854ef03ed69659cb3e455e438408254 100644 (file)
@@ -161,7 +161,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);
index 6bd317f354d40def56cf0a5349502e11eabe4623..11e09474070effee2a78e66ab5f43e705a317b71 100644 (file)
@@ -50,7 +50,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)
index 62b1eff6aecdfa36dfaf620d06b34ee2e6b4b8fd..a95cb8394f4328207189386d819b4c313813427b 100644 (file)
@@ -717,7 +717,7 @@ int btrfs_resize_loopback_fd(int fd, uint64_t new_size, bool grow_only) {
         _cleanup_free_ char *p = NULL, *loop = NULL, *backing = NULL;
         _cleanup_close_ int loop_fd = -1, backing_fd = -1;
         struct stat st;
-        dev_t dev;
+        dev_t dev = 0;
         int r;
 
         /* btrfs cannot handle file systems < 16M, hence use this as minimum */
index 4840c3ebf4149fc7658e7f3f2c204fb6219f8235..58f00e6daec180c910bb72ff4cf83efd0c7c1ec3 100644 (file)
@@ -50,7 +50,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)
index 9e4c3b0f72834ff44e3c6a418bfbf0e0a801944c..775a33985613a33c7d5b1e9a51dba1bf236c03ad 100644 (file)
@@ -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);
@@ -421,7 +421,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);
index 9c680a761b262bff0498298006d808660afb3ce5..1cc999b4d3979c2aad12591850a091b29804d2a8 100644 (file)
@@ -1793,7 +1793,7 @@ UnitFileState unit_file_lookup_state(
         UnitFileState state = _UNIT_FILE_STATE_INVALID;
         char **i;
         _cleanup_free_ char *path = NULL;
-        int r;
+        int r = 0;
 
         assert(paths);
 
index 5a3ab3da3ee505f00f2bd235de278f82cbe1a21c..4e1b87814be77556fb940804247b2ff5051b1111 100644 (file)
@@ -990,7 +990,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 */
 
index 8b76531d4f6072f0bc89f27e141d41901f3ce915..605fffcb7a711a6a81e5afa9a4703a17115318b8 100644 (file)
@@ -2882,7 +2882,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)
@@ -3435,7 +3435,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);
index 4f9f5c1344b2e718eba31b8d3260f45f14c260f5..a3295aa997d3997bb565c2fad2da3f6addf48a2a 100644 (file)
@@ -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);
index eadecb99a06d6b6aef4ab2664ff80667ec872ed9..b5f4d4f0948e4c81147ada6659eaa141bfe4fb5b 100644 (file)
@@ -95,7 +95,7 @@ static void run_parent(Pty *pty) {
 
 static void test_pty(void) {
         pid_t pid;
-        Pty *pty;
+        Pty *pty = NULL;
 
         rcvsiz = 0;
         zero(rcvbuf);
index 361de0d18e90d639515fa9e549ef440ba2d1f6fd..86d09bbff21050a3a0d5ff2b7ba344b795ea1673 100644 (file)
@@ -469,7 +469,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);