]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: some automatic coccinelle fixes (#10463)
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Oct 2018 15:07:46 +0000 (17:07 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 19 Oct 2018 15:07:46 +0000 (00:07 +0900)
Nothing fancy, just coccinelle doing its work.

src/basic/cgroup-util.c
src/basic/json.c
src/basic/time-util.c
src/core/cgroup.c
src/journal/journald-syslog.c
src/libsystemd/sd-bus/sd-bus.c
src/test/test-hexdecoct.c

index e010fc7b5ac4122213b9f56b07ce2a0baac8f68e..19723d30843cd457ac4e6ebf388e2cb07c9ca762 100644 (file)
@@ -2123,7 +2123,7 @@ int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path
         r = cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
         if (r < 0)
                 return r;
-        created = !!r;
+        created = r;
 
         /* If we are in the unified hierarchy, we are done now */
         r = cg_all_unified();
index 426ed0328e26ddbc5f584b51131a8897cf8a1019..7590ca98833f67974d14a7578e5c46a047c25049 100644 (file)
@@ -1763,8 +1763,7 @@ static int json_parse_string(const char **p, char **ret) {
 
                         *p = c + 1;
 
-                        *ret = s;
-                        s = NULL;
+                        *ret = TAKE_PTR(s);
                         return JSON_TOKEN_STRING;
                 }
 
@@ -1919,7 +1918,7 @@ static int json_parse_number(const char **p, JsonValue *ret) {
                 } while (strchr("0123456789", *c) && *c != 0);
         }
 
-        if (*c == 'e' || *c == 'E') {
+        if (IN_SET(*c, 'e', 'E')) {
                 is_real = true;
                 c++;
 
index 158e4aaf934c4c6d2a25a213c22937b2c6e1303a..9115c3bf272e84d6c32014fcd66df5cfba8b8da8 100644 (file)
@@ -280,7 +280,7 @@ static char *format_timestamp_internal(
 
         /* Let's not format times with years > 9999 */
         if (t > USEC_TIMESTAMP_FORMATTABLE_MAX) {
-                assert(l >= strlen("--- XXXX-XX-XX XX:XX:XX") + 1);
+                assert(l >= STRLEN("--- XXXX-XX-XX XX:XX:XX") + 1);
                 strcpy(buf, "--- XXXX-XX-XX XX:XX:XX");
                 return buf;
         }
@@ -1026,7 +1026,7 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
                         char *b = e + 1;
 
                         /* Don't allow "0.-0", "3.+1" or "3. 1" */
-                        if (*b == '-' || *b == '+' || isspace(*b))
+                        if (IN_SET(*b, '-', '+') || isspace(*b))
                                 return -EINVAL;
 
                         errno = 0;
@@ -1164,7 +1164,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
                 if (*e == '.') {
                         char *b = e + 1;
 
-                        if (*b == '-' || *b == '+' || isspace(*b))
+                        if (IN_SET(*b, '-', '+') || isspace(*b))
                                 return -EINVAL;
 
                         errno = 0;
index 1e5b564e170c661a206df745378a43cfce45cb37..e4341c62454905bb33442f45d6790a6b0036fa4b 100644 (file)
@@ -343,9 +343,9 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode)
 
         *a = (CGroupDeviceAllow) {
                 .path = TAKE_PTR(d),
-                .r = isempty(mode) || !!strchr(mode, 'r'),
-                .w = isempty(mode) || !!strchr(mode, 'w'),
-                .m = isempty(mode) || !!strchr(mode, 'm'),
+                .r = isempty(mode) || strchr(mode, 'r'),
+                .w = isempty(mode) || strchr(mode, 'w'),
+                .m = isempty(mode) || strchr(mode, 'm'),
         };
 
         LIST_PREPEND(device_allow, c->device_allow, a);
@@ -1579,7 +1579,7 @@ static int unit_create_cgroup(
         r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, u->cgroup_path);
         if (r < 0)
                 return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", u->cgroup_path);
-        created = !!r;
+        created = r;
 
         /* Start watching it */
         (void) unit_watch_cgroup(u);
index 4dbf42c53bc2cde9e879a43d73e7b4934194fc89..a60a259bc49e587d5b1f2c3aba3708dea906a307 100644 (file)
@@ -407,7 +407,7 @@ void server_process_syslog_message(
         }
 
         if (syslog_ts_len > 0) {
-                const size_t hlen = strlen("SYSLOG_TIMESTAMP=");
+                const size_t hlen = STRLEN("SYSLOG_TIMESTAMP=");
 
                 t = newa(char, hlen + syslog_ts_len);
                 memcpy(t, "SYSLOG_TIMESTAMP=", hlen);
@@ -424,7 +424,7 @@ void server_process_syslog_message(
         iovec[n++] = IOVEC_MAKE_STRING(msg_msg);
 
         if (store_raw) {
-                const size_t hlen = strlen("SYSLOG_RAW=");
+                const size_t hlen = STRLEN("SYSLOG_RAW=");
 
                 msg_raw = new(char, hlen + raw_len);
                 if (!msg_raw) {
index 85558d9c05620d2a27109fd23cf4537157d01092..bc7d00c3d045b16be0e5dec5ca094eb60456adaa 100644 (file)
@@ -1419,11 +1419,9 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
                 if (!in_charset(p, "0123456789") || *p == '\0') {
                         if (!machine_name_is_valid(p) || got_forward_slash)
                                 return -EINVAL;
-                        else {
-                                m = p;
-                                p = NULL;
-                                goto interpret_port_as_machine_old_syntax;
-                        }
+
+                        m = TAKE_PTR(p);
+                        goto interpret_port_as_machine_old_syntax;
                 }
         }
 
index a972ddcef7c41b4519e62e4208f13757180eb27d..6e9b94b93314fee193c5dfc53031be5b4fea772f 100644 (file)
@@ -84,7 +84,7 @@ static void test_unhexmem_one(const char *s, size_t l, int retval) {
                         l = strlen(s);
 
                 assert_se(hex = hexmem(mem, len));
-                answer = strndupa(s ?: "", l);
+                answer = strndupa(strempty(s), l);
                 assert_se(streq(delete_chars(answer, WHITESPACE), hex));
         }
 }