fix gcc warnings about uninitialized variables

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;
             ^
This commit is contained in:
Harald Hoyer 2015-03-27 12:02:49 +01:00
parent 47d45d3cde
commit a7f7d1bde4
27 changed files with 37 additions and 37 deletions

View 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)

View 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;

View 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);

View 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)

View 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;

View 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 */

View 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);

View 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

View 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))

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);

View 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

View 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);

View 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)

View 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 */

View 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)

View 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);

View 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);

View 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 */

View 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);

View 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);

View 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);

View 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);