[tor-commits] [tor/master] Tidy up compare_routerinfo_by_ipv{4, 6} to match better.

dgoulet at torproject.org dgoulet at torproject.org
Thu Sep 24 13:33:12 UTC 2020


commit 3196de33a567bb3126652ffbadf8c7d31eff4887
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Sep 23 11:48:20 2020 -0400

    Tidy up compare_routerinfo_by_ipv{4,6} to match better.
---
 src/feature/dirauth/dirvote.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index a60112a1c6..a27dde6f56 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -4215,19 +4215,16 @@ MOCK_IMPL(uint32_t,dirserv_get_bandwidth_for_router_kb,
 STATIC int
 compare_routerinfo_by_ipv4(const void **a, const void **b)
 {
-  const routerinfo_t *first = *(routerinfo_t **)a;
-  const routerinfo_t *second = *(routerinfo_t **)b;
-  // If addresses are equal, use other comparison criterions
-  int addr_comparison = tor_addr_compare(&(first->ipv4_addr),
-                                         &(second->ipv4_addr), CMP_EXACT);
-  if (addr_comparison == 0) {
+  const routerinfo_t *first = *(const routerinfo_t **)a;
+  const routerinfo_t *second = *(const routerinfo_t **)b;
+  const tor_addr_t *first_ipv4 = &first->ipv4_addr;
+  const tor_addr_t *second_ipv4 = &first->ipv4_addr;
+  int comparison = tor_addr_compare(first_ipv4, second_ipv4, CMP_EXACT);
+  if (comparison == 0) {
+    // If addresses are equal, use other comparison criteria
     return compare_routerinfo_usefulness(first, second);
   } else {
-    // Otherwise, compare the addresses
-    if (addr_comparison < 0 )
-      return -1;
-    else
-      return 1;
+    return comparison;
   }
 }
 
@@ -4238,12 +4235,12 @@ compare_routerinfo_by_ipv4(const void **a, const void **b)
 STATIC int
 compare_routerinfo_by_ipv6(const void **a, const void **b)
 {
-  const routerinfo_t *first = *(routerinfo_t **)a;
-  const routerinfo_t *second = *(routerinfo_t **)b;
+  const routerinfo_t *first = *(const routerinfo_t **)a;
+  const routerinfo_t *second = *(const routerinfo_t **)b;
   const tor_addr_t *first_ipv6 = &(first->ipv6_addr);
   const tor_addr_t *second_ipv6 = &(second->ipv6_addr);
   int comparison = tor_addr_compare(first_ipv6, second_ipv6, CMP_EXACT);
-  // If addresses are equal, use other comparison criterions
+  // If addresses are equal, use other comparison criteria
   if (comparison == 0)
     return compare_routerinfo_usefulness(first, second);
   else





More information about the tor-commits mailing list