chiark / gitweb /
clang: fix some issues found with clang-analyzer v17
authorLennart Poettering <lennart@poettering.net>
Sat, 22 Jan 2011 01:18:59 +0000 (02:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 22 Jan 2011 01:19:16 +0000 (02:19 +0100)
src/cgroup.c
src/cryptsetup.c
src/load-fragment.c
src/manager.c
src/pam-module.c
src/swap.c
src/sysctl.c
src/systemctl.c
src/tmpfiles.c

index 64082d0dc6b64140636d1f10ee209e4fa9deecf3..392736f987f82d1b23f3ce9705005e3dc618e99e 100644 (file)
@@ -404,17 +404,16 @@ char *cgroup_bonding_to_string(CGroupBonding *b) {
 pid_t cgroup_bonding_search_main_pid(CGroupBonding *b) {
         FILE *f;
         pid_t pid = 0, npid;
-        int r;
 
         assert(b);
 
         if (!b->ours)
                 return 0;
 
-        if ((r = cg_enumerate_processes(b->controller, b->path, &f)) < 0)
+        if (cg_enumerate_processes(b->controller, b->path, &f) < 0)
                 return 0;
 
-        while ((r = cg_read_pid(f, &npid)) > 0)  {
+        while (cg_read_pid(f, &npid) > 0)  {
 
                 if (npid == pid)
                         continue;
index f543a05055715aa1f380ef476885b0c9d074ee2a..c80572aed9672f26c0255cbac561182b21a017dc 100644 (file)
@@ -386,6 +386,7 @@ int main(int argc, char *argv[]) {
                 if (try >= opt_tries) {
                         log_error("Too many attempts.");
                         r = EXIT_FAILURE;
+                        goto finish;
                 }
 
         } else if (streq(argv[1], "detach")) {
index 44b2cf06c115f88adb2e9d93052fed934ac93963..acceb9b51f3e6803d005058f36a086d96d56f710 100644 (file)
@@ -191,7 +191,6 @@ static int config_parse_listen(
                 void *data,
                 void *userdata) {
 
-        int r;
         SocketPort *p;
         Socket *s;
 
@@ -217,7 +216,7 @@ static int config_parse_listen(
         } else {
                 p->type = SOCKET_SOCKET;
 
-                if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
+                if (socket_address_parse(&p->address, rvalue) < 0) {
                         log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
                         free(p);
                         return 0;
@@ -289,14 +288,14 @@ static int config_parse_nice(
                 void *userdata) {
 
         ExecContext *c = data;
-        int priority, r;
+        int priority;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &priority)) < 0) {
+        if (safe_atoi(rvalue, &priority) < 0) {
                 log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename, line, rvalue);
                 return 0;
         }
@@ -322,14 +321,14 @@ static int config_parse_oom_score_adjust(
                 void *userdata) {
 
         ExecContext *c = data;
-        int oa, r;
+        int oa;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &oa)) < 0) {
+        if (safe_atoi(rvalue, &oa) < 0) {
                 log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -506,14 +505,13 @@ static int config_parse_usec(
                 void *userdata) {
 
         usec_t *usec = data;
-        int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = parse_usec(rvalue, usec)) < 0) {
+        if (parse_usec(rvalue, usec) < 0) {
                 log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -893,14 +891,13 @@ static int config_parse_timer_slack_nsec(
 
         ExecContext *c = data;
         unsigned long u;
-        int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atolu(rvalue, &u)) < 0) {
+        if (safe_atolu(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -928,7 +925,7 @@ static int config_parse_limit(
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atollu(rvalue, &u)) < 0) {
+        if (safe_atollu(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -985,14 +982,14 @@ static int config_parse_sysv_priority(
                 void *userdata) {
 
         int *priority = data;
-        int r, i;
+        int i;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
+        if (safe_atoi(rvalue, &i) < 0 || i < 0) {
                 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1012,14 +1009,14 @@ static int config_parse_fsck_passno(
                 void *userdata) {
 
         int *passno = data;
-        int r, i;
+        int i;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
+        if (safe_atoi(rvalue, &i) || i < 0) {
                 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1104,7 +1101,6 @@ static int config_parse_timer(
 
         Timer *t = data;
         usec_t u;
-        int r;
         TimerValue *v;
         TimerBase b;
 
@@ -1118,7 +1114,7 @@ static int config_parse_timer(
                 return 0;
         }
 
-        if ((r = parse_usec(rvalue, &u)) < 0) {
+        if (parse_usec(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1379,7 +1375,6 @@ static int config_parse_env_file(
                         if (feof(f))
                                 break;
 
-                        r = -errno;
                         log_error("[%s:%u] Failed to read environment file '%s', ignoring: %m", filename, line, rvalue);
                         r = 0;
                         goto finish;
@@ -1431,7 +1426,6 @@ static int config_parse_ip_tos(
                 void *userdata) {
 
         int *ip_tos = data, x;
-        int r;
 
         assert(filename);
         assert(lvalue);
@@ -1439,7 +1433,7 @@ static int config_parse_ip_tos(
         assert(data);
 
         if ((x = ip_tos_from_string(rvalue)) < 0)
-                if ((r = safe_atoi(rvalue, &x)) < 0) {
+                if (safe_atoi(rvalue, &x) < 0) {
                         log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
                         return 0;
                 }
index 013b26b6c965ad95b64ae3334e1cf1a8f74d7d1f..2714df1152f38631965a302fe5cf77ec0dad30ff 100644 (file)
@@ -2428,7 +2428,6 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
         union sockaddr_union sa;
         int n = 0;
         char *message = NULL;
-        ssize_t r;
 
         /* Don't generate plymouth events if the service was already
          * started and we're just deserializing */
@@ -2472,7 +2471,7 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
         }
 
         errno = 0;
-        if ((r = write(fd, message, n + 1)) != n + 1) {
+        if (write(fd, message, n + 1) != n + 1) {
 
                 if (errno != EPIPE &&
                     errno != EAGAIN &&
index 52507a4cbdb94b0a0516be3e277450c7b36ccf1a..fc3aac185d72b618e4ffd24b58fc6cc11770afe7 100644 (file)
@@ -46,7 +46,9 @@ static int parse_argv(pam_handle_t *handle,
                       char ***controllers) {
 
         unsigned i;
+#if 0
         bool controller_set = false;
+#endif
 
         assert(argc >= 0);
         assert(argc == 0 || argv);
@@ -104,7 +106,9 @@ static int parse_argv(pam_handle_t *handle,
                                 *controllers = l;
                         }
 
+#if 0
                         controller_set = true;
+#endif
 
                 } else {
                         pam_syslog(handle, LOG_ERR, "Unknown parameter '%s'.", argv[i]);
index 23a98dd63f12070e309095f8819d53d6cd97f409..9a253beea2c026ade0a5d77e3f67339716af9657 100644 (file)
@@ -1090,7 +1090,7 @@ int swap_fd_event(Manager *m, int events) {
         assert(m);
         assert(events & EPOLLPRI);
 
-        if ((r == swap_load_proc_swaps(m, true)) < 0) {
+        if ((r = swap_load_proc_swaps(m, true)) < 0) {
                 log_error("Failed to reread /proc/swaps: %s", strerror(-r));
 
                 /* Reset flags, just in case, for late calls */
index 38ea2d18bc2a48bcc85b17e17d547c58c7061bf0..a8a9422ac35a9192a23af62d22b2800c6ea9430e 100644 (file)
@@ -43,6 +43,7 @@ static void apply_sysctl(const char *property, const char *value) {
         if (!(p = new(char, sizeof(PROC_SYS_PREFIX) + strlen(property)))) {
                 log_error("Out of memory");
                 exit_code = -ENOMEM;
+                return;
         }
 
         n = stpcpy(p, PROC_SYS_PREFIX);
index fb3430048cd7f7aef5e9234832774513731f543a..8cdc01aa49566f2bf5275f1fc49e6fdb74e223ba 100644 (file)
@@ -502,8 +502,10 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                 c++;
         }
 
-        qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
-        output_units_list(unit_infos, c);
+        if (c > 0) {
+                qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
+                output_units_list(unit_infos, c);
+        }
 
         r = 0;
 
index 984eaf0de192538f0209fa3880a8b03ab8f3f86d..d242dac7dc0652f25e21d7778e3901915ed38180 100644 (file)
@@ -474,7 +474,7 @@ static void item_free(Item *i) {
 static int parse_line(const char *fname, unsigned line, const char *buffer, const char *prefix) {
         Item *i;
         char *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
-        int r, n;
+        int r;
 
         assert(fname);
         assert(line >= 1);
@@ -485,19 +485,19 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, cons
                 return -ENOMEM;
         }
 
-        if ((n = sscanf(buffer,
-                        "%c "
-                        "%ms "
-                        "%ms "
-                        "%ms "
-                        "%ms "
-                        "%ms",
-                        &i->type,
-                        &i->path,
-                        &mode,
-                        &user,
-                        &group,
-                        &age)) < 2) {
+        if (sscanf(buffer,
+                   "%c "
+                   "%ms "
+                   "%ms "
+                   "%ms "
+                   "%ms "
+                   "%ms",
+                   &i->type,
+                   &i->path,
+                   &mode,
+                   &user,
+                   &group,
+                   &age) < 2) {
                 log_error("[%s:%u] Syntax error.", fname, line);
                 r = -EIO;
                 goto finish;