chiark / gitweb /
tree-wide: drop !! casts to booleans
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Jun 2018 14:02:03 +0000 (16:02 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
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

src/basic/format-table.c
src/basic/verbs.c
src/basic/virt.c
src/login/logind-dbus.c
src/shared/bus-util.c
src/shared/conf-parser.c

index 8340133be66a7a4ee570893d8c283252be1c693b..c967642dff9131f37b25524efd2f8019f566b72b 100644 (file)
@@ -572,7 +572,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
                         break;
 
                 case TABLE_BOOLEAN:
-                        buffer.b = !!va_arg(ap, int);
+                        buffer.b = va_arg(ap, int);
                         data = &buffer.b;
                         break;
 
index 743aed5e4043a544c6044be22a5cce0a47173cf0..a52cd2ad9cfb93d419ca719d21c1d04fcbb8fc54 100644 (file)
@@ -81,7 +81,7 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
                 if (name)
                         found = streq(name, verbs[i].verb);
                 else
-                        found = !!(verbs[i].flags & VERB_DEFAULT);
+                        found = verbs[i].flags & VERB_DEFAULT;
 
                 if (found) {
                         verb = &verbs[i];
index 3b2f1b9172d1b944b2d56175711c770867374abe..dfc384ede1b2151c28b8ef8c06d917f119a49675 100644 (file)
@@ -57,7 +57,7 @@ static int detect_vm_cpuid(void) {
         if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
                 return VIRTUALIZATION_NONE;
 
-        hypervisor = !!(ecx & 0x80000000U);
+        hypervisor = ecx & 0x80000000U;
 
         if (hypervisor) {
                 union {
index 507368604911774a57efae577f27ff79e14c4d4a..26a4ed889817b69a971d5202bccdc88ece7069a0 100644 (file)
@@ -245,9 +245,9 @@ static int property_get_preparing(
         assert(m);
 
         if (streq(property, "PreparingForShutdown"))
-                b = !!(m->action_what & INHIBIT_SHUTDOWN);
+                b = m->action_what & INHIBIT_SHUTDOWN;
         else
-                b = !!(m->action_what & INHIBIT_SLEEP);
+                b = m->action_what & INHIBIT_SLEEP;
 
         return sd_bus_message_append(reply, "b", b);
 }
index 020fa885af1c66753d704f66ce532f45910ee0b6..e69b53ea6fa7ee979d513c88f94aae492187edbc 100644 (file)
@@ -1094,9 +1094,9 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, unsigne
                         return r;
 
                 if (flags & BUS_MAP_BOOLEAN_AS_BOOL)
-                        * (bool*) userdata = !!b;
+                        *(bool*) userdata = b;
                 else
-                        * (int*) userdata = b;
+                        *(int*) userdata = b;
 
                 return 0;
         }
@@ -1413,7 +1413,7 @@ int bus_property_set_bool(
         if (r < 0)
                 return r;
 
-        *(bool *) userdata = !!b;
+        *(bool*) userdata = b;
         return 0;
 }
 
index db74a7fdb61f487b1ef63ce0b37333f243092df7..a150f89401cea86da6970d3fed320bc4804f1293 100644 (file)
@@ -50,6 +50,7 @@
 //#include "rlimit-util.h"
 //#include "rlimit-util.h"
 //#include "rlimit-util.h"
+//#include "rlimit-util.h"
 
 int config_item_table_lookup(
                 const void *table,
@@ -656,7 +657,7 @@ int config_parse_bool(const char* unit,
                 return fatal ? -ENOEXEC : 0;
         }
 
-        *b = !!k;
+        *b = k;
         return 0;
 }