]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: CMP()ify all the things
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2018 13:57:40 +0000 (15:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2018 15:45:53 +0000 (17:45 +0200)
Let's employ coccinelle to fix everything up automatically for us.

coccinelle/cmp.cocci [new file with mode: 0644]
src/basic/btrfs-util.c
src/basic/format-table.c
src/basic/string-util.c
src/core/socket.c
src/journal/journal-file.c
src/libsystemd/sd-event/sd-event.c
src/resolve/resolved-mdns.c

diff --git a/coccinelle/cmp.cocci b/coccinelle/cmp.cocci
new file mode 100644 (file)
index 0000000..a34cbe5
--- /dev/null
@@ -0,0 +1,28 @@
+@@
+expression x, y;
+@@
+- if (x < y)
+-         return -1;
+- if (x > y)
+-         return 1;
+- return 0;
++ return CMP(x, y);
+@@
+expression x, y;
+@@
+- if (x < y)
+-         return -1;
+- else if (x > y)
+-         return 1;
+- return 0;
++ return CMP(x, y);
+@@
+expression x, y;
+@@
+- if (x < y)
+-         return -1;
+- else if (x > y)
+-         return 1;
+- else
+-         return 0;
++ return CMP(x, y);
index 1c9c5fd162b9ce890465a61fc5dd37add1889617..cb8361e4af9fdae95dba4fcdcd987652aab651e1 100644 (file)
@@ -418,12 +418,7 @@ static int btrfs_ioctl_search_args_compare(const struct btrfs_ioctl_search_args
         if (args->key.min_type > args->key.max_type)
                 return 1;
 
-        if (args->key.min_offset < args->key.max_offset)
-                return -1;
-        if (args->key.min_offset > args->key.max_offset)
-                return 1;
-
-        return 0;
+        return CMP(args->key.min_offset, args->key.max_offset);
 }
 
 #define FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args)                  \
index 5c99c398c2d6ed8ed3a81834ce8ec33a5f0ec91c..10e15c9d709de2c90238f5fe1dc1516a9f0093e8 100644 (file)
@@ -688,32 +688,16 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
                         return 0;
 
                 case TABLE_TIMESTAMP:
-                        if (a->timestamp < b->timestamp)
-                                return -1;
-                        if (a->timestamp > b->timestamp)
-                                return 1;
-                        return 0;
+                        return CMP(a->timestamp, b->timestamp);
 
                 case TABLE_TIMESPAN:
-                        if (a->timespan < b->timespan)
-                                return -1;
-                        if (a->timespan > b->timespan)
-                                return 1;
-                        return 0;
+                        return CMP(a->timespan, b->timespan);
 
                 case TABLE_SIZE:
-                        if (a->size < b->size)
-                                return -1;
-                        if (a->size > b->size)
-                                return 1;
-                        return 0;
+                        return CMP(a->size, b->size);
 
                 case TABLE_UINT32:
-                        if (a->uint32 < b->uint32)
-                                return -1;
-                        if (a->uint32 > b->uint32)
-                                return 1;
-                        return 0;
+                        return CMP(a->uint32, b->uint32);
 
                 default:
                         ;
@@ -721,12 +705,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
         }
 
         /* Generic fallback using the orginal order in which the cells where added. */
-        if (index_a < index_b)
-                return -1;
-        if (index_a > index_b)
-                return 1;
-
-        return 0;
+        return CMP(index_a, index_b);
 }
 
 static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
index c6dad5275fe16b08e4fac292bb12315845479a52..a3be35847df4852525ba254dca79e5e1647abfe7 100644 (file)
@@ -398,12 +398,7 @@ int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m) {
         if (r != 0)
                 return r;
 
-        if (n < m)
-                return -1;
-        else if (n > m)
-                return 1;
-        else
-                return 0;
+        return CMP(n, m);
 }
 
 bool chars_intersect(const char *a, const char *b) {
index 649904d4062715ec7c69619867588d267622efc7..06e9956157f01e644c7812a568cb700d82ac4a70 100644 (file)
@@ -496,11 +496,7 @@ static int peer_address_compare_func(const void *a, const void *b) {
         case AF_INET6:
                 return memcmp(&x->peer.in6.sin6_addr, &y->peer.in6.sin6_addr, sizeof(x->peer.in6.sin6_addr));
         case AF_VSOCK:
-                if (x->peer.vm.svm_cid < y->peer.vm.svm_cid)
-                        return -1;
-                if (x->peer.vm.svm_cid > y->peer.vm.svm_cid)
-                        return 1;
-                return 0;
+                return CMP(x->peer.vm.svm_cid, y->peer.vm.svm_cid);
         }
         assert_not_reached("Black sheep in the family!");
 }
index 9c92d6751658399915fee9cd653d1085907513af..0587c432c1cd5aeb876df0e2ee0d5ab8ed8ea0d2 100644 (file)
@@ -2661,12 +2661,7 @@ int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
                 return 1;
 
         /* Finally, compare by contents */
-        if (af->current_xor_hash < bf->current_xor_hash)
-                return -1;
-        if (af->current_xor_hash > bf->current_xor_hash)
-                return 1;
-
-        return 0;
+        return CMP(af->current_xor_hash, bf->current_xor_hash);
 }
 
 static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
index 720acfb0c79892f864df75d17cefe9a7ecd05b77..66dc9541e09134ab07fcddbd58a5666057e24310 100644 (file)
@@ -419,12 +419,7 @@ static int exit_prioq_compare(const void *a, const void *b) {
                 return 1;
 
         /* Lower priority values first */
-        if (x->priority < y->priority)
-                return -1;
-        if (x->priority > y->priority)
-                return 1;
-
-        return 0;
+        return CMP(x->priority, y->priority);
 }
 
 static void free_clock_data(struct clock_data *d) {
@@ -1579,12 +1574,7 @@ static int inode_data_compare(const void *a, const void *b) {
         if (x->dev > y->dev)
                 return 1;
 
-        if (x->ino < y->ino)
-                return -1;
-        if (x->ino > y->ino)
-                return 1;
-
-        return 0;
+        return CMP(x->ino, y->ino);
 }
 
 static void inode_data_hash_func(const void *p, struct siphash *state) {
index e70138181a9b1d730c3e3643b0e564c77a938eae..32868180cee080732fddf1022189dbfa10544713 100644 (file)
@@ -101,12 +101,7 @@ static int proposed_rrs_cmp(DnsResourceRecord **x, unsigned x_size, DnsResourceR
                         return r;
         }
 
-        if (x_size < y_size)
-                return -1;
-        if (x_size > y_size)
-                return 1;
-
-        return 0;
+        return CMP(x_size, y_size);
 }
 
 static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, DnsResourceRecord ***ret_rrs) {