mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-20 14:03:39 +03:00
tree-wide: drop !! casts to booleans
They are not needed, because anything that is non-zero is converted to true. C11: > 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the > value compares equal to 0; otherwise, the result is 1. https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c
This commit is contained in:
parent
37e744e866
commit
5d904a6aaa
12
coccinelle/bool-cast.cocci
Normal file
12
coccinelle/bool-cast.cocci
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
@@
|
||||||
|
bool b;
|
||||||
|
expression y;
|
||||||
|
@@
|
||||||
|
- b = !!(y);
|
||||||
|
+ b = y;
|
||||||
|
@@
|
||||||
|
bool b;
|
||||||
|
expression y;
|
||||||
|
@@
|
||||||
|
- b = !!y;
|
||||||
|
+ b = y;
|
@ -1833,7 +1833,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_man = !!r;
|
arg_man = r;
|
||||||
} else
|
} else
|
||||||
arg_man = true;
|
arg_man = true;
|
||||||
|
|
||||||
@ -1847,7 +1847,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_generators = !!r;
|
arg_generators = r;
|
||||||
} else
|
} else
|
||||||
arg_generators = true;
|
arg_generators = true;
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ int btrfs_subvol_get_info_fd(int fd, uint64_t subvol_id, BtrfsSubvolInfo *ret) {
|
|||||||
(usec_t) le32toh(ri->otime.nsec) / NSEC_PER_USEC;
|
(usec_t) le32toh(ri->otime.nsec) / NSEC_PER_USEC;
|
||||||
|
|
||||||
ret->subvol_id = subvol_id;
|
ret->subvol_id = subvol_id;
|
||||||
ret->read_only = !!(le64toh(ri->flags) & BTRFS_ROOT_SUBVOL_RDONLY);
|
ret->read_only = le64toh(ri->flags) & BTRFS_ROOT_SUBVOL_RDONLY;
|
||||||
|
|
||||||
assert_cc(sizeof(ri->uuid) == sizeof(ret->uuid));
|
assert_cc(sizeof(ri->uuid) == sizeof(ret->uuid));
|
||||||
memcpy(&ret->uuid, ri->uuid, sizeof(ret->uuid));
|
memcpy(&ret->uuid, ri->uuid, sizeof(ret->uuid));
|
||||||
|
@ -572,7 +572,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TABLE_BOOLEAN:
|
case TABLE_BOOLEAN:
|
||||||
buffer.b = !!va_arg(ap, int);
|
buffer.b = va_arg(ap, int);
|
||||||
data = &buffer.b;
|
data = &buffer.b;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
|||||||
if (name)
|
if (name)
|
||||||
found = streq(name, verbs[i].verb);
|
found = streq(name, verbs[i].verb);
|
||||||
else
|
else
|
||||||
found = !!(verbs[i].flags & VERB_DEFAULT);
|
found = verbs[i].flags & VERB_DEFAULT;
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
verb = &verbs[i];
|
verb = &verbs[i];
|
||||||
|
@ -56,7 +56,7 @@ static int detect_vm_cpuid(void) {
|
|||||||
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
|
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
|
||||||
return VIRTUALIZATION_NONE;
|
return VIRTUALIZATION_NONE;
|
||||||
|
|
||||||
hypervisor = !!(ecx & 0x80000000U);
|
hypervisor = ecx & 0x80000000U;
|
||||||
|
|
||||||
if (hypervisor) {
|
if (hypervisor) {
|
||||||
union {
|
union {
|
||||||
|
@ -1972,7 +1972,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_expect_reply = !!r;
|
arg_expect_reply = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_AUTO_START:
|
case ARG_AUTO_START:
|
||||||
@ -1982,7 +1982,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_auto_start = !!r;
|
arg_auto_start = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_ALLOW_INTERACTIVE_AUTHORIZATION:
|
case ARG_ALLOW_INTERACTIVE_AUTHORIZATION:
|
||||||
@ -1992,7 +1992,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_allow_interactive_authorization = !!r;
|
arg_allow_interactive_authorization = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_TIMEOUT:
|
case ARG_TIMEOUT:
|
||||||
@ -2011,7 +2011,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_augment_creds = !!r;
|
arg_augment_creds = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ARG_WATCH_BIND:
|
case ARG_WATCH_BIND:
|
||||||
@ -2021,7 +2021,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_watch_bind = !!r;
|
arg_watch_bind = r;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
|
@ -563,7 +563,7 @@ static int property_get_bind_paths(
|
|||||||
assert(property);
|
assert(property);
|
||||||
assert(reply);
|
assert(reply);
|
||||||
|
|
||||||
ro = !!strstr(property, "ReadOnly");
|
ro = strstr(property, "ReadOnly");
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
|
r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -322,7 +322,7 @@ static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs,
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
ro = !!(flags & MS_RDONLY);
|
ro = flags & MS_RDONLY;
|
||||||
if (ro)
|
if (ro)
|
||||||
flags ^= MS_RDONLY;
|
flags ^= MS_RDONLY;
|
||||||
}
|
}
|
||||||
|
@ -3215,7 +3215,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|||||||
* The PID file might actually be created by a START_POST
|
* The PID file might actually be created by a START_POST
|
||||||
* script. In that case don't worry if the loading fails. */
|
* script. In that case don't worry if the loading fails. */
|
||||||
|
|
||||||
has_start_post = !!s->exec_command[SERVICE_EXEC_START_POST];
|
has_start_post = s->exec_command[SERVICE_EXEC_START_POST];
|
||||||
r = service_load_pid_file(s, !has_start_post);
|
r = service_load_pid_file(s, !has_start_post);
|
||||||
if (!has_start_post && r < 0) {
|
if (!has_start_post && r < 0) {
|
||||||
r = service_demand_pid_file(s);
|
r = service_demand_pid_file(s);
|
||||||
|
@ -302,7 +302,7 @@ int main(int argc, char *argv[]) {
|
|||||||
(void) cg_get_root_path(&cgroup);
|
(void) cg_get_root_path(&cgroup);
|
||||||
in_container = detect_container() > 0;
|
in_container = detect_container() > 0;
|
||||||
|
|
||||||
use_watchdog = !!getenv("WATCHDOG_USEC");
|
use_watchdog = getenv("WATCHDOG_USEC");
|
||||||
watchdog_device = getenv("WATCHDOG_DEVICE");
|
watchdog_device = getenv("WATCHDOG_DEVICE");
|
||||||
if (watchdog_device) {
|
if (watchdog_device) {
|
||||||
r = watchdog_set_device(watchdog_device);
|
r = watchdog_set_device(watchdog_device);
|
||||||
|
@ -378,7 +378,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->level_prefix = !!r;
|
s->level_prefix = r;
|
||||||
s->state = STDOUT_STREAM_FORWARD_TO_SYSLOG;
|
s->state = STDOUT_STREAM_FORWARD_TO_SYSLOG;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->forward_to_syslog = !!r;
|
s->forward_to_syslog = r;
|
||||||
s->state = STDOUT_STREAM_FORWARD_TO_KMSG;
|
s->state = STDOUT_STREAM_FORWARD_TO_KMSG;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->forward_to_kmsg = !!r;
|
s->forward_to_kmsg = r;
|
||||||
s->state = STDOUT_STREAM_FORWARD_TO_CONSOLE;
|
s->state = STDOUT_STREAM_FORWARD_TO_CONSOLE;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ static int stdout_stream_line(StdoutStream *s, char *p, LineBreak line_break) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->forward_to_console = !!r;
|
s->forward_to_console = r;
|
||||||
s->state = STDOUT_STREAM_RUNNING;
|
s->state = STDOUT_STREAM_RUNNING;
|
||||||
|
|
||||||
/* Try to save the stream, so that journald can be restarted and we can recover */
|
/* Try to save the stream, so that journald can be restarted and we can recover */
|
||||||
|
@ -242,9 +242,9 @@ static int property_get_preparing(
|
|||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
if (streq(property, "PreparingForShutdown"))
|
if (streq(property, "PreparingForShutdown"))
|
||||||
b = !!(m->action_what & INHIBIT_SHUTDOWN);
|
b = m->action_what & INHIBIT_SHUTDOWN;
|
||||||
else
|
else
|
||||||
b = !!(m->action_what & INHIBIT_SLEEP);
|
b = m->action_what & INHIBIT_SLEEP;
|
||||||
|
|
||||||
return sd_bus_message_append(reply, "b", b);
|
return sd_bus_message_append(reply, "b", b);
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ int dhcp6_request_address(Link *link, int ir) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
else
|
else
|
||||||
running = !!r;
|
running = r;
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &inf_req);
|
r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &inf_req);
|
||||||
|
@ -1090,9 +1090,9 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, unsigne
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (flags & BUS_MAP_BOOLEAN_AS_BOOL)
|
if (flags & BUS_MAP_BOOLEAN_AS_BOOL)
|
||||||
* (bool*) userdata = !!b;
|
*(bool*) userdata = b;
|
||||||
else
|
else
|
||||||
* (int*) userdata = b;
|
*(int*) userdata = b;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1403,7 +1403,7 @@ int bus_property_set_bool(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
*(bool *) userdata = !!b;
|
*(bool*) userdata = b;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ static int condition_test_kernel_command_line(Condition *c) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
equal = !!strchr(c->parameter, '=');
|
equal = strchr(c->parameter, '=');
|
||||||
|
|
||||||
for (p = line;;) {
|
for (p = line;;) {
|
||||||
_cleanup_free_ char *word = NULL;
|
_cleanup_free_ char *word = NULL;
|
||||||
|
@ -632,7 +632,7 @@ int config_parse_bool(const char* unit,
|
|||||||
return fatal ? -ENOEXEC : 0;
|
return fatal ? -ENOEXEC : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*b = !!k;
|
*b = k;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ static int map_ntp_message(sd_bus *bus, const char *member, sd_bus_message *m, s
|
|||||||
|
|
||||||
memcpy(p->reference.str, d, sz);
|
memcpy(p->reference.str, d, sz);
|
||||||
|
|
||||||
p->spike = !!b;
|
p->spike = b;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user