diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-09-23 01:44:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-09-23 01:45:34 +0200 |
commit | f8440af5febb18ddfd2bc7a94b771284f0b7b310 (patch) | |
tree | 83172e88ffe4251d3fe7765a1f5874e1a5135f1a | |
parent | 8ea913b2eaadbd92e069ea6b71cc5f5df409decf (diff) |
coverity: change a few things so that coverity doesn't show so many false positives
-rw-r--r-- | src/dbus-manager.c | 2 | ||||
-rw-r--r-- | src/hostnamed.c | 2 | ||||
-rw-r--r-- | src/install.c | 2 | ||||
-rw-r--r-- | src/loginctl.c | 48 | ||||
-rw-r--r-- | src/nspawn.c | 6 | ||||
-rw-r--r-- | src/strv.c | 9 | ||||
-rw-r--r-- | src/systemctl.c | 20 | ||||
-rw-r--r-- | src/util.c | 8 |
8 files changed, 42 insertions, 55 deletions
diff --git a/src/dbus-manager.c b/src/dbus-manager.c index 822189b103..7b68156abf 100644 --- a/src/dbus-manager.c +++ b/src/dbus-manager.c @@ -300,7 +300,7 @@ static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, free(p); if (access("/proc/cgroups", F_OK) < 0) - e = stpcpy(e, "cgroups-missing "); + stpcpy(e, "cgroups-missing "); t = strstrip(buf); diff --git a/src/hostnamed.c b/src/hostnamed.c index 0db78c096b..b47f227705 100644 --- a/src/hostnamed.c +++ b/src/hostnamed.c @@ -233,7 +233,7 @@ static int write_data_other(void) { assert(name[p]); if (isempty(data[p])) { - l = strv_env_unset(l, name[p]); + strv_env_unset(l, name[p]); continue; } diff --git a/src/install.c b/src/install.c index 53dd26fd7f..cfbd50ead9 100644 --- a/src/install.c +++ b/src/install.c @@ -1904,7 +1904,7 @@ int unit_file_get_list( } else if (r > 0) { f->state = UNIT_FILE_DISABLED; goto found; - } else if (r == 0) { + } else { f->state = UNIT_FILE_STATIC; goto found; } diff --git a/src/loginctl.c b/src/loginctl.c index 53058d07a7..ba8020df23 100644 --- a/src/loginctl.c +++ b/src/loginctl.c @@ -64,6 +64,8 @@ static bool on_tty(void) { } static void pager_open_if_enabled(void) { + + /* Cache result before we open the pager */ on_tty(); if (!arg_no_pager) @@ -1146,7 +1148,7 @@ finish: } static int activate(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1157,6 +1159,8 @@ static int activate(DBusConnection *bus, char **args, unsigned n) { dbus_error_init(&error); for (i = 1; i < n; i++) { + DBusMessage *reply; + m = dbus_message_new_method_call( "org.freedesktop.login1", "/org/freedesktop/login1", @@ -1195,16 +1199,13 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; } static int kill_session(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1218,6 +1219,8 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) { arg_kill_who = "all"; for (i = 1; i < n; i++) { + DBusMessage *reply; + m = dbus_message_new_method_call( "org.freedesktop.login1", "/org/freedesktop/login1", @@ -1255,16 +1258,13 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; } static int enable_linger(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1278,6 +1278,7 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) { b = streq(args[0], "enable-linger"); for (i = 1; i < n; i++) { + DBusMessage *reply; uint32_t u; uid_t uid; @@ -1327,16 +1328,13 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; } static int terminate_user(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1349,6 +1347,7 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) { for (i = 1; i < n; i++) { uint32_t u; uid_t uid; + DBusMessage *reply; m = dbus_message_new_method_call( "org.freedesktop.login1", @@ -1394,16 +1393,13 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; } static int kill_user(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1417,6 +1413,7 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) { arg_kill_who = "all"; for (i = 1; i < n; i++) { + DBusMessage *reply; uid_t uid; uint32_t u; @@ -1465,16 +1462,13 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; } static int attach(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1486,6 +1480,8 @@ static int attach(DBusConnection *bus, char **args, unsigned n) { dbus_error_init(&error); for (i = 2; i < n; i++) { + DBusMessage *reply; + m = dbus_message_new_method_call( "org.freedesktop.login1", "/org/freedesktop/login1", @@ -1523,9 +1519,6 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; @@ -1581,7 +1574,7 @@ finish: } static int terminate_seat(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int ret = 0; DBusError error; unsigned i; @@ -1592,6 +1585,8 @@ static int terminate_seat(DBusConnection *bus, char **args, unsigned n) { dbus_error_init(&error); for (i = 1; i < n; i++) { + DBusMessage *reply; + m = dbus_message_new_method_call( "org.freedesktop.login1", "/org/freedesktop/login1", @@ -1627,9 +1622,6 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return ret; diff --git a/src/nspawn.c b/src/nspawn.c index 8c3cf6bfaa..6f484e78e0 100644 --- a/src/nspawn.c +++ b/src/nspawn.c @@ -197,8 +197,10 @@ static int mount_all(const char *dest) { /* Fix the timezone, if possible */ if (asprintf(&where, "%s/%s", dest, "/etc/localtime") >= 0) { - mount("/etc/localtime", where, "bind", MS_BIND, NULL); - mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL); + + if (mount("/etc/localtime", where, "bind", MS_BIND, NULL) >= 0) + mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL); + free(where); } diff --git a/src/strv.c b/src/strv.c index 640ae3f0a3..bb309d9f92 100644 --- a/src/strv.c +++ b/src/strv.c @@ -67,7 +67,8 @@ void strv_free(char **l) { char **strv_copy(char **l) { char **r, **k; - if (!(k = r = new(char*, strv_length(l)+1))) + k = r = new(char*, strv_length(l)+1); + if (!k) return NULL; if (l) @@ -198,7 +199,8 @@ char **strv_merge_concat(char **a, char **b, const char *suffix) { if (!b) return strv_copy(a); - if (!(r = new(char*, strv_length(a)+strv_length(b)+1))) + r = new(char*, strv_length(a) + strv_length(b) + 1); + if (!r) return NULL; k = r; @@ -324,7 +326,8 @@ char **strv_append(char **l, const char *s) { if (!s) return strv_copy(l); - if (!(r = new(char*, strv_length(l)+2))) + r = new(char*, strv_length(l)+2); + if (!r) return NULL; for (k = r; *l; k++, l++) diff --git a/src/systemctl.c b/src/systemctl.c index e85a2fd44c..fdff2d1250 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -137,6 +137,8 @@ static bool on_tty(void) { } static void pager_open_if_enabled(void) { + + /* Cache result before we open the pager */ on_tty(); if (arg_no_pager) @@ -1055,7 +1057,7 @@ finish: } static int load_unit(DBusConnection *bus, char **args) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; DBusError error; int r; char **name; @@ -1066,6 +1068,7 @@ static int load_unit(DBusConnection *bus, char **args) { assert(args); STRV_FOREACH(name, args+1) { + DBusMessage *reply; if (!(m = dbus_message_new_method_call( "org.freedesktop.systemd1", @@ -1103,9 +1106,6 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return r; @@ -1795,7 +1795,7 @@ finish: } static int kill_unit(DBusConnection *bus, char **args) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int r = 0; DBusError error; char **name; @@ -1812,6 +1812,7 @@ static int kill_unit(DBusConnection *bus, char **args) { arg_kill_mode = streq(arg_kill_who, "all") ? "control-group" : "process"; STRV_FOREACH(name, args+1) { + DBusMessage *reply; if (!(m = dbus_message_new_method_call( "org.freedesktop.systemd1", @@ -1851,9 +1852,6 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return r; @@ -3231,7 +3229,7 @@ finish: } static int reset_failed(DBusConnection *bus, char **args) { - DBusMessage *m = NULL, *reply = NULL; + DBusMessage *m = NULL; int r; DBusError error; char **name; @@ -3243,6 +3241,7 @@ static int reset_failed(DBusConnection *bus, char **args) { return daemon_reload(bus, args); STRV_FOREACH(name, args+1) { + DBusMessage *reply; if (!(m = dbus_message_new_method_call( "org.freedesktop.systemd1", @@ -3279,9 +3278,6 @@ finish: if (m) dbus_message_unref(m); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); return r; diff --git a/src/util.c b/src/util.c index 6a9fffbf3d..2eb6ba74fc 100644 --- a/src/util.c +++ b/src/util.c @@ -782,13 +782,7 @@ int read_full_file(const char *fn, char **contents, size_t *size) { } } - if (buf) - buf[l] = 0; - else if (!(buf = calloc(1, 1))) { - r = -errno; - goto finish; - } - + buf[l] = 0; *contents = buf; buf = NULL; |