diff options
-rw-r--r-- | coccinelle/cmp.cocci | 28 | ||||
-rw-r--r-- | src/basic/btrfs-util.c | 7 | ||||
-rw-r--r-- | src/basic/format-table.c | 31 | ||||
-rw-r--r-- | src/basic/string-util.c | 7 | ||||
-rw-r--r-- | src/core/socket.c | 6 | ||||
-rw-r--r-- | src/journal/journal-file.c | 7 | ||||
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 14 | ||||
-rw-r--r-- | src/resolve/resolved-mdns.c | 7 |
8 files changed, 40 insertions, 67 deletions
diff --git a/coccinelle/cmp.cocci b/coccinelle/cmp.cocci new file mode 100644 index 0000000000..a34cbe5bf6 --- /dev/null +++ b/coccinelle/cmp.cocci @@ -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); diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index 1c9c5fd162..cb8361e4af 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -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) \ diff --git a/src/basic/format-table.c b/src/basic/format-table.c index 5c99c398c2..10e15c9d70 100644 --- a/src/basic/format-table.c +++ b/src/basic/format-table.c @@ -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) { diff --git a/src/basic/string-util.c b/src/basic/string-util.c index c6dad5275f..a3be35847d 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -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) { diff --git a/src/core/socket.c b/src/core/socket.c index 649904d406..06e9956157 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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!"); } diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 9c92d67516..0587c432c1 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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) { diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 720acfb0c7..66dc9541e0 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -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) { diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c index e70138181a..32868180ce 100644 --- a/src/resolve/resolved-mdns.c +++ b/src/resolve/resolved-mdns.c @@ -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) { |