aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-09-23 11:48:20 -0400
committerNick Mathewson <nickm@torproject.org>2020-09-23 11:48:20 -0400
commit3196de33a567bb3126652ffbadf8c7d31eff4887 (patch)
tree27807901457964bbd5c5e66dce9596eb12847a24 /src
parent81c05e1e986b5f301d59d520366d8583828729fa (diff)
downloadtor-3196de33a567bb3126652ffbadf8c7d31eff4887.tar.gz
tor-3196de33a567bb3126652ffbadf8c7d31eff4887.zip
Tidy up compare_routerinfo_by_ipv{4,6} to match better.
Diffstat (limited to 'src')
-rw-r--r--src/feature/dirauth/dirvote.c25
1 files 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