Merge pull request #19169 from keszybz/reenable-maybe-unitialized-warning

Fix a bunch of maybe-unitialized warnings but don't enable the warning yet
This commit is contained in:
Luca Boccassi
2021-04-01 09:36:46 +01:00
committed by GitHub
16 changed files with 161 additions and 160 deletions
+2 -1
View File
@@ -660,7 +660,7 @@ int cg_remove_xattr(const char *controller, const char *path, const char *name)
int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
_cleanup_fclose_ FILE *f = NULL;
const char *fs, *controller_str;
const char *fs, *controller_str = NULL; /* silence gcc warning about unitialized variable */
int unified, r;
assert(pid >= 0);
@@ -720,6 +720,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
continue;
*e = 0;
assert(controller_str);
r = string_contains_word(l, ",", controller_str);
if (r < 0)
return r;
+6 -7
View File
@@ -515,10 +515,10 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
ALTERNATE_VALUE,
} state = WORD;
const char *e, *word = format, *test_value;
const char *e, *word = format, *test_value = NULL; /* test_value is initialized to appease gcc */
char *k;
_cleanup_free_ char *r = NULL;
size_t i, len;
size_t i, len = 0; /* len is initialized to appease gcc */
int nest = 0;
assert(format);
@@ -581,13 +581,12 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
word = e+1;
state = WORD;
} else if (*e == ':') {
if (!(flags & REPLACE_ENV_ALLOW_EXTENDED))
if (flags & REPLACE_ENV_ALLOW_EXTENDED) {
len = e - word - 2;
state = TEST;
} else
/* Treat this as unsupported syntax, i.e. do no replacement */
state = WORD;
else {
len = e-word-2;
state = TEST;
}
}
break;
+4 -3
View File
@@ -121,7 +121,7 @@ int write_string_stream_ts(
const struct timespec *ts) {
bool needs_nl;
int r, fd;
int r, fd = -1;
assert(f);
assert(line);
@@ -140,8 +140,8 @@ int write_string_stream_ts(
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
/* If STDIO buffering was disabled, then let's append the newline character to the string itself, so
* that the write goes out in one go, instead of two */
/* If STDIO buffering was disabled, then let's append the newline character to the string
* itself, so that the write goes out in one go, instead of two */
line = strjoina(line, "\n");
needs_nl = false;
@@ -164,6 +164,7 @@ int write_string_stream_ts(
if (ts) {
const struct timespec twice[2] = {*ts, *ts};
assert(fd >= 0);
if (futimens(fd, twice) < 0)
return -errno;
}
+2 -1
View File
@@ -14,6 +14,7 @@
#include <sys/types.h>
#include <sys/un.h>
#include "errno-util.h"
#include "macro.h"
#include "missing_network.h"
#include "missing_socket.h"
@@ -264,7 +265,7 @@ static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
socklen_t sl = sizeof(v);
if (getsockopt(fd, level, optname, &v, &sl) < 0)
return -errno;
return negative_errno();
if (sl != sizeof(v))
return -EIO;
+1 -1
View File
@@ -1367,7 +1367,7 @@ static int status_welcome(void) {
static int write_container_id(void) {
const char *c;
int r;
int r = 0; /* silence gcc warning about r being unitialized below */
c = getenv("container");
if (isempty(c))
+7 -9
View File
@@ -1008,7 +1008,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_free_ char *friendly = NULL;
int keyslot = arg_key_slot, r;
size_t decrypted_key_size;
size_t decrypted_key_size = 0; /* Silence gcc warning about unitialized variable */
assert(cd);
assert(name);
@@ -1058,15 +1058,12 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
&policy_hash, &policy_hash_size,
&keyslot,
&token);
if (r == -ENXIO) {
if (r == -ENXIO)
/* No further TPM2 tokens found in the LUKS2 header.*/
if (found_some)
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
"No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking.");
else
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
"No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking.");
}
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
found_some
? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking."
: "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking.");
if (r < 0)
return r;
@@ -1091,6 +1088,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
if (r != -EAGAIN) /* EAGAIN means: no tpm2 chip found */
return r;
}
assert(decrypted_key);
if (!monitor) {
/* We didn't find the TPM2 device. In this case, watch for it via udev. Let's create
+16 -6
View File
@@ -86,8 +86,10 @@ static int bus_error_name_to_errno(const char *name) {
if (m->code == BUS_ERROR_MAP_END_MARKER)
break;
if (streq(m->name, name))
if (streq(m->name, name)) {
assert(m->code > 0);
return m->code;
}
}
m = ALIGN_TO_PTR(__start_SYSTEMD_BUS_ERROR_MAP, sizeof(void*));
@@ -103,8 +105,10 @@ static int bus_error_name_to_errno(const char *name) {
continue;
}
if (streq(m->name, name))
if (streq(m->name, name)) {
assert(m->code > 0);
return m->code;
}
m++;
}
@@ -232,6 +236,7 @@ finish:
}
int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_list ap) {
int r;
if (!name)
return 0;
@@ -253,23 +258,28 @@ int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_li
e->_need_free = 1;
}
return -bus_error_name_to_errno(name);
r = bus_error_name_to_errno(name);
assert(r > 0);
return -r;
}
_public_ int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...) {
int r;
if (format) {
int r;
va_list ap;
va_start(ap, format);
r = bus_error_setfv(e, name, format, ap);
assert(!name || r < 0);
va_end(ap);
return r;
}
return sd_bus_error_set(e, name, NULL);
r = sd_bus_error_set(e, name, NULL);
assert(!name || r < 0);
return r;
}
_public_ int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e) {
@@ -455,7 +465,7 @@ _public_ int sd_bus_error_set_errno(sd_bus_error *e, int error) {
if (!e)
return -error;
if (error == 0)
return -error;
return 0;
assert_return(!bus_error_is_dirty(e), -EINVAL);
+1 -1
View File
@@ -3171,7 +3171,7 @@ static int process_child(sd_event *e, int64_t threshold, int64_t *ret_min_priori
zero(s->child.siginfo);
if (waitid(P_PID, s->child.pid, &s->child.siginfo,
WNOHANG | (s->child.options & WEXITED ? WNOWAIT : 0) | s->child.options) < 0)
return -errno;
return negative_errno();
if (s->child.siginfo.si_pid != 0) {
bool zombie = IN_SET(s->child.siginfo.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);
+1 -2
View File
@@ -183,7 +183,7 @@ static DnsTransactionState dns_query_candidate_state(DnsQueryCandidate *c) {
if (c->error_code != 0)
return DNS_TRANSACTION_ERRNO;
SET_FOREACH(t, c->transactions) {
SET_FOREACH(t, c->transactions)
switch (t->state) {
@@ -213,7 +213,6 @@ static DnsTransactionState dns_query_candidate_state(DnsQueryCandidate *c) {
break;
}
}
return state;
}
+5 -2
View File
@@ -98,8 +98,11 @@ static int bus_message_read_dns_one(
if (r < 0)
return r;
if (!dns_server_address_valid(family, &a))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid DNS server address");
if (!dns_server_address_valid(family, &a)) {
r = sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid DNS server address");
assert(r < 0);
return r;
}
if (extended) {
r = sd_bus_message_read(message, "q", &port);
+2 -1
View File
@@ -300,7 +300,8 @@ int config_parse(
(void) stat_warn_permissions(filename, &st);
mtime = timespec_load(&st.st_mtim);
}
} else
mtime = 0;
for (;;) {
_cleanup_free_ char *buf = NULL;
+3 -1
View File
@@ -280,7 +280,7 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection,
int conf_files_cat(const char *root, const char *name) {
_cleanup_strv_free_ char **dirs = NULL, **files = NULL;
_cleanup_free_ char *path = NULL;
char **prefixes, **prefix;
char **prefix, **prefixes = NULL; /* explicit initialization to appease gcc */
bool is_collection;
const char *extension;
char **t;
@@ -289,6 +289,8 @@ int conf_files_cat(const char *root, const char *name) {
r = guess_type(&name, &prefixes, &is_collection, &extension);
if (r < 0)
return r;
assert(prefixes);
assert(extension);
STRV_FOREACH(prefix, prefixes) {
assert(endswith(*prefix, "/"));
+11 -7
View File
@@ -448,13 +448,16 @@ static int varlink_write(Varlink *v) {
assert(v->fd >= 0);
/* We generally prefer recv()/send() (mostly because of MSG_NOSIGNAL) but also want to be compatible
* with non-socket IO, hence fall back automatically */
if (!v->prefer_read_write) {
* with non-socket IO, hence fall back automatically.
*
* Use a local variable to help gcc figure out that we set 'n' in all cases. */
bool prefer_write = v->prefer_read_write;
if (!prefer_write) {
n = send(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size, MSG_DONTWAIT|MSG_NOSIGNAL);
if (n < 0 && errno == ENOTSOCK)
v->prefer_read_write = true;
prefer_write = v->prefer_read_write = true;
}
if (v->prefer_read_write)
if (prefer_write)
n = write(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size);
if (n < 0) {
if (errno == EAGAIN)
@@ -531,12 +534,13 @@ static int varlink_read(Varlink *v) {
rs = v->input_buffer_allocated - (v->input_buffer_index + v->input_buffer_size);
if (!v->prefer_read_write) {
bool prefer_read = v->prefer_read_write;
if (!prefer_read) {
n = recv(v->fd, v->input_buffer + v->input_buffer_index + v->input_buffer_size, rs, MSG_DONTWAIT);
if (n < 0 && errno == ENOTSOCK)
v->prefer_read_write = true;
prefer_read = v->prefer_read_write = true;
}
if (v->prefer_read_write)
if (prefer_read)
n = read(v->fd, v->input_buffer + v->input_buffer_index + v->input_buffer_size, rs);
if (n < 0) {
if (errno == EAGAIN)
+3 -1
View File
@@ -307,7 +307,9 @@ int start_unit(int argc, char *argv[], void *userdata) {
method = verb_to_method(argv[0]);
job_type = verb_to_job_type(argv[0]);
mode = arg_job_mode;
}
} else
method = job_type = mode = NULL;
one_name = NULL;
}
} else {
+5 -12
View File
@@ -103,22 +103,15 @@ static int setup_tests(bool *run_ambient) {
nobody = getpwnam(NOBODY_USER_NAME);
if (!nobody)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Could not find nobody user: %m");
return log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Couldn't find 'nobody' user: %m");
test_uid = nobody->pw_uid;
test_gid = nobody->pw_gid;
*run_ambient = false;
r = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);
/* There's support for PR_CAP_AMBIENT if the prctl() call
* succeeded or error code was something else than EINVAL. The
* EINVAL check should be good enough to rule out false
* positives. */
if (r >= 0 || errno != EINVAL)
*run_ambient = true;
/* There's support for PR_CAP_AMBIENT if the prctl() call succeeded or error code was something else
* than EINVAL. The EINVAL check should be good enough to rule out false positives. */
*run_ambient = r >= 0 || errno != EINVAL;
return 0;
}
@@ -249,7 +242,7 @@ static void test_ensure_cap_64bit(void) {
}
int main(int argc, char *argv[]) {
bool run_ambient;
bool run_ambient = false; /* unnecessary initialization to silence gcc warning */
test_setup_logging(LOG_INFO);