]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Reduce branches in comparators
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 7 Jul 2017 01:09:23 +0000 (21:09 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 7 Jul 2017 01:09:23 +0000 (21:09 -0400)
31 files changed:
src/lib/io/network.c
src/lib/io/track.c
src/lib/io/worker.c
src/lib/util/dict.c
src/lib/util/event.c
src/lib/util/heap.c
src/lib/util/inet.c
src/lib/util/misc.c
src/lib/util/pair.c
src/main/cf_file.c
src/main/client.c
src/main/cond_eval.c
src/main/dl.c
src/main/listen.c
src/main/map_proc.c
src/main/modules.c
src/main/pool.c
src/main/radclient.c
src/main/state.c
src/main/threads.c
src/main/trigger.c
src/main/xlat_func.c
src/modules/proto_bfd/proto_bfd.c
src/modules/proto_ldap_sync/sync.c
src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_files/rlm_files.c
src/modules/rlm_python/rlm_python.c
src/modules/rlm_redis/cluster.c
src/modules/rlm_redis_ippool/rlm_redis_ippool_tool.c
src/protocols/dhcpv4/base.c

index 72ec047318fe5b312005455a4ef50f1205aceb08..3a60a7c1e0de1d456bb8354309a42b8799042942 100644 (file)
@@ -95,38 +95,27 @@ static void fr_network_post_event(fr_event_list_t *el, struct timeval *now, void
 
 static int worker_cmp(void const *one, void const *two)
 {
-       fr_network_worker_t const *a = one;
-       fr_network_worker_t const *b = two;
+       fr_network_worker_t const *a = one, *b = two;
 
-       if (a->cpu_time < b->cpu_time) return -1;
-       if (a->cpu_time > b->cpu_time) return +1;
-
-       return 0;
+       return (a->cpu_time < b->cpu_time) - (a->cpu_time > b->cpu_time);
 }
 
 static int reply_cmp(void const *one, void const *two)
 {
-       fr_channel_data_t const *a = one;
-       fr_channel_data_t const *b = two;
-
-       if (a->priority < b->priority) return -1;
-       if (a->priority > b->priority) return +1;
+       fr_channel_data_t const *a = one, *b = two;
+       int ret;
 
-       if (a->m.when < b->m.when) return -1;
-       if (a->m.when > b->m.when) return +1;
+       ret = (a->priority > b->priority) - (a->priority < b->priority);
+       if (ret != 0) return ret;
 
-       return 0;
+       return (a->m.when > b->m.when) - (a->m.when < b->m.when);
 }
 
 static int socket_cmp(void const *one, void const *two)
 {
-       fr_network_socket_t const *a = one;
-       fr_network_socket_t const *b = two;
-
-       if (a->listen < b->listen) return -1;
-       if (a->listen > b->listen) return +1;
+       fr_network_socket_t const *a = one, *b = two;
 
-       return 0;
+       return (a->listen > b->listen) - (a->listen < b->listen);
 }
 
 
index c9dffa8471256ef2279fee28cd19d76c8c878a55..1b05ac21c12570b232e003715f25f0d582cf370b 100644 (file)
@@ -55,19 +55,15 @@ struct fr_tracking_t {
 
 static int entry_cmp(void const *one, void const *two)
 {
-       fr_tracking_entry_t const *a = one;
-       fr_tracking_entry_t const *b = two;
+       fr_tracking_entry_t const *a = one, *b = two;
 
        /*
         *      Check Code and Identifier.
         *
         *      But NOT the Request Authenticator.
         */
-       if (a->data[0] < b->data[0]) return -1;
-       if (a->data[0] > b->data[0]) return +1;
-
-       if (a->data[1] < b->data[1]) return -1;
-       if (a->data[1] > b->data[1]) return +1;
+       if (a->data[0] != b->data[0]) return a->data[0] - b->data[0];
+       if (a->data[1] != b->data[1]) return a->data[1] - b->data[1];
 
        return memcmp(a->src_dst, b->src_dst, a->src_dst_size);
 }
index dd1c735b0ee68bab0e9389a77e1faa8ca3b83e51..7d6c87415c30feb2f9b67ae37b0f5c4a7da29054 100644 (file)
@@ -941,16 +941,13 @@ static int fr_worker_pre_event(void *ctx, struct timeval *wake)
  */
 static int worker_message_cmp(void const *one, void const *two)
 {
-       fr_channel_data_t const *a = one;
-       fr_channel_data_t const *b = two;
+       fr_channel_data_t const *a = one, *b = two;
+       int ret;
 
-       if (a->priority < b->priority) return -1;
-       if (a->priority > b->priority) return +1;
+       ret = (a->priority > b->priority) - (a->priority < b->priority);
+       if (ret != 0) return ret;
 
-       if (a->m.when < b->m.when) return -1;
-       if (a->m.when > b->m.when) return +1;
-
-       return 0;
+       return (a->m.when > b->m.when) - (a->m.when < b->m.when);
 }
 
 /**
@@ -958,16 +955,13 @@ static int worker_message_cmp(void const *one, void const *two)
  */
 static int worker_request_cmp(void const *one, void const *two)
 {
-       REQUEST const *a = one;
-       REQUEST const *b = two;
+       REQUEST const *a = one, *b = two;
+       int ret;
 
-       if (a->async->priority < b->async->priority) return -1;
-       if (a->async->priority > b->async->priority) return +1;
+       ret = (a->async->priority > b->async->priority) - (a->async->priority < b->async->priority);
+       if (ret != 0) return ret;
 
-       if (a->async->recv_time < b->async->recv_time) return -1;
-       if (a->async->recv_time > b->async->recv_time) return +1;
-
-       return 0;
+       return (a->async->recv_time > b->async->recv_time) - (a->async->recv_time < b->async->recv_time);
 }
 
 /** Destroy a worker.
index dd7dcace694743d4649e24bf92e9d83c9f13f21b..b8ad6c44233dc73e3dae414bf933dc7730bf8d6a 100644 (file)
@@ -298,8 +298,7 @@ static uint32_t dict_attr_name_hash(void const *data)
  */
 static int dict_attr_name_cmp(void const *one, void const *two)
 {
-       fr_dict_attr_t const *a = one;
-       fr_dict_attr_t const *b = two;
+       fr_dict_attr_t const *a = one, *b = two;
 
        return strcasecmp(a->name, b->name);
 }
@@ -322,16 +321,16 @@ static uint32_t dict_attr_combo_hash(void const *data)
  */
 static int dict_attr_combo_cmp(void const *one, void const *two)
 {
-       fr_dict_attr_t const *a = one;
-       fr_dict_attr_t const *b = two;
+       fr_dict_attr_t const *a = one, *b = two;
+       int ret;
 
-       if (a->parent < b->parent) return -1;
-       if (a->parent > b->parent) return +1;
+       ret = (a->parent < b->parent) - (a->parent > b->parent);
+       if (ret != 0) return ret;
 
-       if (a->type < b->type) return -1;
-       if (a->type > b->type) return +1;
+       ret = (a->type < b->type) - (a->type > b->type);
+       if (ret != 0) return ret;
 
-       return a->attr - b->attr;
+       return (a->attr > b->attr) - (a->attr < b->attr);
 }
 
 /** Wrap name hash function for fr_dict_vendor_t
index c8cc531d92aecbd7c235231e6cb625c7ba735502..1dfc99cdcc1c7391ca29ab56b8d052ad6d64cc67 100644 (file)
@@ -149,8 +149,7 @@ struct fr_event_list_t {
 static int fr_event_timer_cmp(void const *a, void const *b)
 {
        int                     ret;
-       fr_event_timer_t const  *ev_a = a;
-       fr_event_timer_t const  *ev_b = b;
+       fr_event_timer_t const  *ev_a = a, *ev_b = b;
 
        return (ret = ((ev_a->when.tv_sec < ev_b->when.tv_sec) - (ev_a->when.tv_sec > ev_b->when.tv_sec))) ?
                ret :
@@ -168,8 +167,7 @@ static int fr_event_timer_cmp(void const *a, void const *b)
  */
 static int fr_event_fd_cmp(void const *a, void const *b)
 {
-       fr_event_fd_t const *ev_a = a;
-       fr_event_fd_t const *ev_b = b;
+       fr_event_fd_t const *ev_a = a, *ev_b = b;
 
        return (ev_a->fd < ev_b->fd) - (ev_a->fd > ev_b->fd);
 }
index 8e021f90f868bcec4c3e5e20e8bbfef5a26557f3..b2c905778a87df4b007d0239e40bfaf34171cf1a 100644 (file)
@@ -278,14 +278,9 @@ typedef struct heap_thing {
  */
 static int heap_cmp(void const *one, void const *two)
 {
-       heap_thing const *a;
-       heap_thing const *b;
-
-       a = (heap_thing const *) one;
-       b = (heap_thing const *) two;
+       heap_thing const *a = one, *b = two;
 
        return a->data - b->data;
-
 }
 
 #define ARRAY_SIZE (1024)
index 4aaed1df8319f25dba781064f83bb1221732e6bf..18967894d0e04d9bbdc311fda3bde7d49323f83d 100644 (file)
@@ -1081,11 +1081,8 @@ int fr_ipaddr_from_ifindex(fr_ipaddr_t *out, int fd, int af, int if_index)
  */
 int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
 {
-       if (a->af < b->af) return -1;
-       if (a->af > b->af) return +1;
-
-       if (a->prefix < b->prefix) return -1;
-       if (a->prefix > b->prefix) return +1;
+       if (a->af != b->af) return a->af - b->af;
+       if (a->prefix != b->prefix) return a->prefix - b->prefix;
 
        switch (a->af) {
        case AF_INET:
@@ -1095,12 +1092,8 @@ int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
 
 #ifdef HAVE_STRUCT_SOCKADDR_IN6
        case AF_INET6:
-               if (a->scope_id < b->scope_id) return -1;
-               if (a->scope_id > b->scope_id) return +1;
-
-               return memcmp(&a->addr.v6,
-                             &b->addr.v6,
-                             sizeof(a->addr.v6));
+               if (a->scope_id != b->scope_id) return a->scope_id - b->scope_id;
+               return memcmp(&a->addr.v6, &b->addr.v6, sizeof(a->addr.v6));
 #endif
 
        default:
index 5f3a821799ec0f92b61595d3fea83c4d281f7019..1bbfad4e6c81f9f1f51d2c47081673daa8eb24b3 100644 (file)
@@ -1047,13 +1047,12 @@ void fr_timeval_divide(struct timeval *out, struct timeval const *in, int diviso
  */
 int fr_timeval_cmp(struct timeval const *a, struct timeval const *b)
 {
-       if (a->tv_sec > b->tv_sec) return +1;
-       if (a->tv_sec < b->tv_sec) return -1;
+       int ret;
 
-       if (a->tv_usec > b->tv_usec) return +1;
-       if (a->tv_usec < b->tv_usec) return -1;
+       ret = (a->tv_sec > b->tv_sec) - (a->tv_sec < b->tv_sec);
+       if (ret != 0) return ret;
 
-       return 0;
+       return (a->tv_usec > b->tv_usec) - (a->tv_usec < b->tv_usec);
 }
 
 /** Create timeval from a string
@@ -1228,10 +1227,7 @@ bool fr_multiply(uint64_t *result, uint64_t lhs, uint64_t rhs)
  */
 int8_t fr_pointer_cmp(void const *a, void const *b)
 {
-       if (a < b) return -1;
-       if (a == b) return 0;
-
-       return 1;
+       return (a > b) - (a < b);
 }
 
 /** Quick sort an array of pointers using a comparator
@@ -1289,9 +1285,7 @@ int fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length)
        int result = 0;
        size_t i;
 
-       for (i = 0; i < length; i++) {
-               result |= a[i] ^ b[i];
-       }
+       for (i = 0; i < length; i++) result |= a[i] ^ b[i];
 
        return result;          /* 0 is OK, !0 is !OK, just like memcmp */
 }
index 2fa6c981e86c8e6e25f5330bf32b6c3a118e133b..dc58d138227b57195b33b3e8cede34f8a503296c 100644 (file)
@@ -863,11 +863,7 @@ int8_t fr_pair_cmp_by_da_tag(void const *a, void const *b)
        cmp = fr_pointer_cmp(my_a->da, my_b->da);
        if (cmp != 0) return cmp;
 
-       if (my_a->tag < my_b->tag) return -1;
-
-       if (my_a->tag > my_b->tag) return 1;
-
-       return 0;
+       return (my_a->tag > my_b->tag) - (my_a->tag < my_b->tag);
 }
 
 /** Order attributes by their attribute number, and tag
@@ -1042,29 +1038,20 @@ int fr_pair_list_cmp(VALUE_PAIR *a, VALUE_PAIR *b)
 {
        vp_cursor_t a_cursor, b_cursor;
        VALUE_PAIR *a_p, *b_p;
-       int ret;
 
        for (a_p = fr_pair_cursor_init(&a_cursor, &a), b_p = fr_pair_cursor_init(&b_cursor, &b);
             a_p && b_p;
             a_p = fr_pair_cursor_next(&a_cursor), b_p = fr_pair_cursor_next(&b_cursor)) {
+               int ret;
+
                /* Same VP, no point doing expensive checks */
-               if (a_p == b_p) {
-                       continue;
-               }
+               if (a_p == b_p) continue;
 
-               if (a_p->da < b_p->da) {
-                       return -1;
-               }
-               if (a_p->da > b_p->da) {
-                       return 1;
-               }
+               ret = (a_p->da < b_p->da) - (a_p->da > b_p->da);
+               if (ret != 0) return ret;
 
-               if (a_p->tag < b_p->tag) {
-                       return -1;
-               }
-               if (a_p->tag > b_p->tag) {
-                       return 1;
-               }
+               ret = (a_p->tag < b_p->tag) - (a_p->tag > b_p->tag);
+               if (ret != 0) return ret;
 
                ret = fr_value_box_cmp(&a_p->data, &b_p->data);
                if (ret != 0) {
index ee27b6c3e495ba92e754e63cc464d97ed4d527b1..ee0fc7385bf9f93273b533d58e34d3edfb35aa55 100644 (file)
@@ -409,16 +409,13 @@ static bool cf_template_merge(CONF_SECTION *cs, CONF_SECTION const *template)
  */
 static int _filename_cmp(void const *a, void const *b)
 {
-       cf_file_t const *one = a;
-       cf_file_t const *two = b;
+       cf_file_t const *one = a, *two = b;
+       int ret;
 
-       if (one->buf.st_dev < two->buf.st_dev) return -1;
-       if (one->buf.st_dev > two->buf.st_dev) return +1;
+       ret = (one->buf.st_dev < two->buf.st_dev) - (one->buf.st_dev > two->buf.st_dev);
+       if (ret != 0) return ret;
 
-       if (one->buf.st_ino < two->buf.st_ino) return -1;
-       if (one->buf.st_ino > two->buf.st_ino) return +1;
-
-       return 0;
+       return (one->buf.st_ino < two->buf.st_ino) - (one->buf.st_ino > two->buf.st_ino);
 }
 
 static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
index a88f343766a4cd00e829b9e42e112c43ed5dd0dc..ab9bf6556e41853b218db1be92aae0cd7bbe7350 100644 (file)
@@ -141,8 +141,7 @@ static int client_ipaddr_cmp(void const *one, void const *two)
  */
 static int client_num_cmp(void const *one, void const *two)
 {
-       RADCLIENT const *a = one;
-       RADCLIENT const *b = two;
+       RADCLIENT const *a = one, *b = two;
 
        return (a->number - b->number);
 }
index d530e93134ad899abfd570d119cca7d1e95b221d..d69209529d2d19d53bfea6924a2cce4df88085cb 100644 (file)
@@ -372,7 +372,7 @@ static int cond_normalise_and_cmp(REQUEST *request, fr_cond_t const *c, fr_value
        fr_value_box_t          *rhs = NULL;
 
        fr_dict_attr_t const    *cast = NULL;
-       fr_type_t                       cast_type = FR_TYPE_INVALID;
+       fr_type_t               cast_type = FR_TYPE_INVALID;
 
        fr_value_box_t          lhs_cast, rhs_cast;
        void                    *lhs_cast_buff = NULL, *rhs_cast_buff = NULL;
index 0b833e1e1b8e4615ffef899ca9ecf823f1375c26..85725a923391726630bfb302f2ff86bc064c858f 100644 (file)
@@ -119,47 +119,45 @@ static int dl_init(void);
 
 static int dl_symbol_init_cmp(void const *one, void const *two)
 {
-       dl_symbol_init_t const *a = one;
-       dl_symbol_init_t const *b = two;
+       dl_symbol_init_t const *a = one, *b = two;
+       int ret;
 
        rad_assert(a && b);
 
-       if ((void *)a->func > (void *)b->func) return +1;
-       if ((void *)a->func < (void *)b->func) return -1;
+       ret = ((void *)a->func > (void *)b->func) - ((void *)a->func < (void *)b->func);
+       if (ret != 0) return ret;
 
-       if (a->symbol && !b->symbol) return +1;
-       if (!a->symbol && b->symbol) return -1;
-       if (a->symbol && b->symbol) return strcmp(a->symbol, b->symbol);
+       ret = (a->symbol && !b->symbol) - (!a->symbol && b->symbol);
+       if (ret != 0) return ret;
 
-       return 0;
+       if (!a->symbol && !b->symbol) return 0;
+
+       return strcmp(a->symbol, b->symbol);
 }
 
 static int dl_symbol_free_cmp(void const *one, void const *two)
 {
-       dl_symbol_free_t const *a = one;
-       dl_symbol_free_t const *b = two;
+       dl_symbol_free_t const *a = one, *b = two;
+       int ret;
 
        rad_assert(a && b);
 
-       if ((void *)a->func > (void *)b->func) return +1;
-       if ((void *)a->func < (void *)b->func) return -1;
+       ret = ((void *)a->func > (void *)b->func) - ((void *)a->func < (void *)b->func);
+       if (ret != 0) return ret;
 
-       if (a->symbol && !b->symbol) return +1;
-       if (!a->symbol && b->symbol) return -1;
-       if (a->symbol && b->symbol) return strcmp(a->symbol, b->symbol);
+       ret = (a->symbol && !b->symbol) - (!a->symbol && b->symbol);
+       if (ret != 0) return ret;
 
-       return 0;
+       if (!a->symbol && !b->symbol) return 0;
+
+       return strcmp(a->symbol, b->symbol);
 }
 
 static int dl_inst_cmp(void const *one, void const *two)
 {
-       dl_instance_t const *a = one;
-       dl_instance_t const *b = two;
-
-       if (a->data > b->data) return +1;
-       if (a->data < b->data) return -1;
+       dl_instance_t const *a = one, *b = two;
 
-       return 0;
+       return (a->data > b->data) - (a->data < b->data);
 }
 
 /** Compare the name of two dl_t
index 0e0819e8008d115bffc1b085bd1f49e8df011508..b96a76259884c1793002c55f3328101f10171283 100644 (file)
@@ -1189,9 +1189,7 @@ static CONF_PARSER limit_config[] = {
  */
 static int listener_cmp(void const *one, void const *two)
 {
-       if (one < two) return -1;
-       if (one > two) return +1;
-       return 0;
+       return (one < two) - (one > two);
 }
 
 static int listener_unlink(UNUSED void *ctx, UNUSED void *data)
index b8f23e2e7cb99a2472766f1da00b29427e424ce1..b36ab5bf95e4c34b3cee5d78a6e12078a22ef6a5 100644 (file)
@@ -61,8 +61,7 @@ struct map_proc_inst {
  */
 static int map_proc_cmp(void const *one, void const *two)
 {
-       map_proc_t const *a = one;
-       map_proc_t const *b = two;
+       map_proc_t const *a = one, *b = two;
 
        if (a->length != b->length) return a->length - b->length;
 
index 81bb171c36096e624df0b334687647e047c3b9a7..efd441a1d489e57eaa99498808fb4fae5557194e 100644 (file)
@@ -539,10 +539,7 @@ static int _module_thread_inst_tree_cmp(void const *a, void const *b)
 {
        module_thread_instance_t const *my_a = a, *my_b = b;
 
-       if (my_a->inst > my_b->inst) return +1;
-       if (my_a->inst < my_b->inst) return -1;
-
-       return 0;
+       return (my_a->inst > my_b->inst) - (my_a->inst < my_b->inst);
 }
 
 typedef struct {
index 01e3101d656fb3804a1c2d2e8e5632a96b79fc30..6b5f3f84d6bd201945dcdbb43877358beeddb176 100644 (file)
@@ -165,32 +165,29 @@ static const CONF_PARSER pool_config[] = {
  */
 static int last_reserved_cmp(void const *one, void const *two)
 {
-       fr_pool_connection_t const *a = one;
-       fr_pool_connection_t const *b = two;
+       fr_pool_connection_t const *a = one, *b = two;
+       int ret;
 
-       if (a->last_reserved.tv_sec < b->last_reserved.tv_sec) return -1;
-       if (a->last_reserved.tv_sec > b->last_reserved.tv_sec) return +1;
+       ret = (a->last_reserved.tv_sec < b->last_reserved.tv_sec) - (a->last_reserved.tv_sec > b->last_reserved.tv_sec);
+       if (ret != 0) return ret;
 
-       if (a->last_reserved.tv_usec < b->last_reserved.tv_usec) return -1;
-       if (a->last_reserved.tv_usec > b->last_reserved.tv_usec) return +1;
-
-       return 0;
+       return (a->last_reserved.tv_usec < b->last_reserved.tv_usec) -
+              (a->last_reserved.tv_usec > b->last_reserved.tv_usec);
 }
 
 /** Order connections by released longest ago
  */
 static int last_released_cmp(void const *one, void const *two)
 {
-       fr_pool_connection_t const *a = one;
-       fr_pool_connection_t const *b = two;
+       fr_pool_connection_t const *a = one, *b = two;
+       int ret;
 
-       if (b->last_released.tv_sec < a->last_released.tv_sec) return -1;
-       if (b->last_released.tv_sec > a->last_released.tv_sec) return +1;
+       ret = (b->last_released.tv_sec < a->last_released.tv_sec) -
+             (b->last_released.tv_sec > a->last_released.tv_sec);
+       if (ret != 0) return ret;
 
-       if (b->last_released.tv_usec < a->last_released.tv_usec) return -1;
-       if (b->last_released.tv_usec > a->last_released.tv_usec) return +1;
-
-       return 0;
+       return (b->last_released.tv_usec < a->last_released.tv_usec) -
+              (b->last_released.tv_usec > a->last_released.tv_usec);
 }
 
 /** Removes a connection from the connection list
index 98f3484bdced1196479ea9fb1431e84caeb0122c..253b82620e2e08d19df53c5da9360cb27df2f48e 100644 (file)
@@ -751,11 +751,9 @@ static int radclient_sane(rc_request_t *request)
  */
 static int filename_cmp(void const *one, void const *two)
 {
+       rc_file_pair_t const *a = one, *b = two;
        int cmp;
 
-       rc_file_pair_t const *a = one;
-       rc_file_pair_t const *b = two;
-
        cmp = strcmp(a->packets, b->packets);
        if (cmp != 0) return cmp;
 
index 5ebab52bd1c09b8c39c4d4a9f714b340426f3056..7a9c36a24d04ec8c2894816cda52040d8d10270b 100644 (file)
@@ -130,8 +130,7 @@ static void state_entry_unlink(fr_state_tree_t *state, fr_state_entry_t *entry);
  */
 static int state_entry_cmp(void const *one, void const *two)
 {
-       fr_state_entry_t const *a = one;
-       fr_state_entry_t const *b = two;
+       fr_state_entry_t const *a = one, *b = two;
 
        return memcmp(a->state, b->state, sizeof(a->state));
 }
index be677e1817906e5583846c39649d1c3ae4961acb..1d288f5bd2c1e9f11db92f3b8659a14c6f6d0ac6 100644 (file)
@@ -716,11 +716,11 @@ static int pid_cmp(void const *one, void const *two)
  */
 static int default_cmp(void const *one, void const *two)
 {
-       REQUEST const *a = one;
-       REQUEST const *b = two;
+       REQUEST const *a = one, *b = two;
+       int ret;
 
-       if (a->priority < b->priority) return -1;
-       if (a->priority > b->priority) return +1;
+       ret = (a->priority < b->priority) - (a->priority > b->priority);
+       if (ret != 0) return ret;
 
        return timestamp_cmp(one, two);
 }
@@ -731,14 +731,14 @@ static int default_cmp(void const *one, void const *two)
  */
 static int state_cmp(void const *one, void const *two)
 {
-       REQUEST const *a = one;
-       REQUEST const *b = two;
+       REQUEST const *a = one, *b = two;
+       int ret;
 
        /*
         *      Rounds which are further along go higher in the heap.
         */
-       if (a->packet->rounds > b->packet->rounds) return -1;
-       if (a->packet->rounds < b->packet->rounds) return +1;
+       ret = (a->packet->rounds > b->packet->rounds) - (a->packet->rounds < b->packet->rounds);
+       if (ret != 0) return ret;
 
        return default_cmp(one, two);
 }
index 7542e2a8b34923d1b44596372b21cc94f39c42fc..43c92a548a4d48e61923a7c066fc2052aa953a76 100644 (file)
@@ -107,10 +107,7 @@ static int _trigger_last_fired_cmp(void const *a, void const *b)
 {
        trigger_last_fired_t const *lf_a = a, *lf_b = b;
 
-       if (lf_a->ci < lf_b->ci) return -1;
-       if (lf_a->ci == lf_b->ci) return 0;
-
-       return 1;
+       return (lf_a->ci < lf_b->ci) - (lf_a->ci > lf_b->ci);
 }
 
 /** Set the global trigger section trigger_exec will search in, and register xlats
index 1e3bc68fcfa3a0ab0f25aa4e27e3d085a76ec7ae..3c92143f3018da40270c2e0c865d8316865521c2 100644 (file)
@@ -649,10 +649,11 @@ done:
  */
 static int xlat_cmp(void const *one, void const *two)
 {
-       xlat_t const *a = one;
-       xlat_t const *b = two;
+       xlat_t const *a = one, *b = two;
+       int ret;
 
-       if (a->length != b->length) return a->length - b->length;
+       ret = (a->length > b->length) - (a->length < b->length);
+       if (ret != 0) return ret;
 
        return memcmp(a->name, b->name, a->length);
 }
index 686221f9a2add39b0378211d6cb7b0fd31bfad36..de4fce8635e91e6a7514f5886ca75d3429f59d81 100644 (file)
@@ -1636,8 +1636,7 @@ static int bfd_socket_decode(UNUSED rad_listen_t *listener, UNUSED REQUEST *requ
 
 static int bfd_session_cmp(const void *one, const void *two)
 {
-       const bfd_state_t *a = one;
-       const bfd_state_t *b = two;
+       const bfd_state_t *a = one, *b = two;
 
        return fr_ipaddr_cmp(&a->remote_ipaddr, &b->remote_ipaddr);
 }
index 7a7f061017f8721a68610d12a3f5e0f9684d9cc9..27a1929bf473bcfb0cce07632d7022e070aece8f 100644 (file)
@@ -877,8 +877,7 @@ static int _sync_state_free(sync_state_t *sync)
  */
 static int _sync_cmp(void const *one, void const *two)
 {
-       sync_state_t const *a = one;
-       sync_state_t const *b = two;
+       sync_state_t const *a = one, *b = two;
 
        return a->msgid - b->msgid;
 }
index 36a53f30c5043eb76f8a2c172c817994dffe406b..052a66f72fb40dccdd83ffbcd6317d6c498c197e 100644 (file)
@@ -44,11 +44,11 @@ typedef struct rlm_cache_rbtree_entry {
  */
 static int cache_entry_cmp(void const *one, void const *two)
 {
-       rlm_cache_entry_t const *a = one;
-       rlm_cache_entry_t const *b = two;
+       rlm_cache_entry_t const *a = one, *b = two;
+       int ret;
 
-       if (a->key_len < b->key_len) return -1;
-       if (a->key_len > b->key_len) return +1;
+       ret = (a->key_len > b->key_len) - (a->key_len < b->key_len);
+       if (ret != 0) return ret;
 
        return memcmp(a->key, b->key, a->key_len);
 }
@@ -59,13 +59,9 @@ static int cache_entry_cmp(void const *one, void const *two)
  */
 static int cache_heap_cmp(void const *one, void const *two)
 {
-       rlm_cache_entry_t const *a = one;
-       rlm_cache_entry_t const *b = two;
-
-       if (a->expires < b->expires) return -1;
-       if (a->expires > b->expires) return +1;
+       rlm_cache_entry_t const *a = one, *b = two;
 
-       return 0;
+       return (a->expires > b->expires) - (a->expires < b->expires);
 }
 
 /** Walk over the cache rbtree
index 450f85d79435c186aef4d4305419e3d7d91478c6..fd86d31cf0a94c4266da05eb1152273356df1243 100644 (file)
@@ -106,10 +106,7 @@ static uint32_t detail_hash(void const *data)
 
 static int detail_cmp(void const *a, void const *b)
 {
-       fr_dict_attr_t const *one = a;
-       fr_dict_attr_t const *two = b;
-
-       return one - two;
+       return (a < b) - (a > b);
 }
 
 /*
index ff2edc0fd69cf55bde05c8b4cbb9e19362efe005..31242eea0761a9a56d7acd2845f7749ae0e1c7f3 100644 (file)
@@ -93,8 +93,7 @@ static const CONF_PARSER module_config[] = {
 
 static int pairlist_cmp(void const *a, void const *b)
 {
-       return strcmp(((PAIR_LIST const *)a)->name,
-                     ((PAIR_LIST const *)b)->name);
+       return strcmp(((PAIR_LIST const *)a)->name, ((PAIR_LIST const *)b)->name);
 }
 
 static int getusersfile(TALLOC_CTX *ctx, char const *filename, rbtree_t **ptree)
index c984b1f2358a0f4c48c8389ea8e1d74148112c88..629be823710434481935ffbbed91af9527bc62a1 100644 (file)
@@ -642,9 +642,7 @@ static int _python_inst_cmp(const void *a, const void *b)
 {
        python_thread_state_t const *a_p = a, *b_p = b;
 
-       if (a_p->inst < b_p->inst) return -1;
-       if (a_p->inst > b_p->inst) return +1;
-       return 0;
+       return (a_p->inst < b_p->inst) - (a_p->inst > b_p->inst);
 }
 
 /** Thread safe call to a python function
index 5193917c2ac3b8f0496d1570c6dc75f729612ef6..ec1954bf2d865a27c7a2a1ae9a1887d8babeceda 100644 (file)
@@ -305,18 +305,13 @@ static uint16_t cluster_key_hash(uint8_t const *key, size_t key_len)
  */
 static int _cluster_node_cmp(void const *a, void const *b)
 {
+       cluster_node_t const *my_a = a, *my_b = b;
        int ret;
 
-       cluster_node_t const *my_a = a;
-       cluster_node_t const *my_b = b;
-
        ret = fr_ipaddr_cmp(&my_a->addr.ipaddr, &my_b->addr.ipaddr);
        if (ret != 0) return ret;
 
-       if (my_a->addr.port < my_b->addr.port) return -1;
-       if (my_a->addr.port > my_b->addr.port) return +1;
-
-       return 0;
+       return my_a->addr.port - my_b->addr.port;
 }
 
 /** Reconnect callback to apply new pool config
index 2309f4705f6d484b57d0b38fb2e1f5d549441806..a42c35c8dbe5c581e6c2bbdd7b89756d5a98b743 100644 (file)
@@ -834,20 +834,16 @@ static int8_t pool_cmp(void const *a, void const *b)
 {
        size_t len_a;
        size_t len_b;
-
        int ret;
 
        len_a = talloc_array_length((uint8_t const *)a);
        len_b = talloc_array_length((uint8_t const *)b);
 
-       if (len_a > len_b) return 1;
-       if (len_a < len_b) return -1;
+       ret = (len_a > len_b) - (len_a < len_b);
+       if (ret != 0) return ret;
 
        ret = memcmp(a, b, len_a);
-       if (ret > 0) return 1;
-       if (ret < 0) return -1;
-
-       return 0;
+       return (ret > 0) - (ret < 0);
 }
 
 /** Return the pools available across the cluster
index 0acc44c25eb6ee4bd493f7b531fdfcc49e977617..bf5e30a0dffe4f1a9d0f2eee3fe006a246f2e4db 100644 (file)
@@ -104,8 +104,7 @@ fr_dict_attr_t const *dhcp_option_82;
 
 int8_t fr_dhcpv4_attr_cmp(void const *a, void const *b)
 {
-       VALUE_PAIR const *my_a = a;
-       VALUE_PAIR const *my_b = b;
+       VALUE_PAIR const *my_a = a, *my_b = b;
        fr_dict_attr_t const *a_82, *b_82;
 
        VERIFY_VP(my_a);