aboutsummaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-04-03 19:13:36 -0400
committerNick Mathewson <nickm@torproject.org>2011-04-26 23:54:17 -0400
commit128582cc1f9fd363f3fb2a96b61fde1701a56970 (patch)
treefaffa809cee30d7ab98a48591e3b35586ca4ad0c /src/or/routerlist.c
parent84f0e87c6a6629d047a39f658b7f7c96767219ca (diff)
downloadtor-128582cc1f9fd363f3fb2a96b61fde1701a56970.tar.gz
tor-128582cc1f9fd363f3fb2a96b61fde1701a56970.zip
Simplify calls to routerset_equal
The routerset_equal function explicitly handles NULL inputs, so there's no need to check inputs for NULL before calling it. Also fix a bug in routerset_equal where a non-NULL routerset with no entries didn't get counted as equal to a NULL routerset. This was untriggerable, I think, but potentially annoying down the road.
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index a9a216b2a1..d5e8a6b051 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -5473,14 +5473,12 @@ routerset_needs_geoip(const routerset_t *set)
return set && smartlist_len(set->country_names);
}
-#if 0
/** Return true iff there are no entries in <b>set</b>. */
static int
routerset_is_empty(const routerset_t *set)
{
return !set || smartlist_len(set->list) == 0;
}
-#endif
/** Helper. Return true iff <b>set</b> contains a router based on the other
* provided fields. Return higher values for more specific subentries: a
@@ -5659,10 +5657,15 @@ routerset_to_string(const routerset_t *set)
int
routerset_equal(const routerset_t *old, const routerset_t *new)
{
- if (old == NULL && new == NULL)
+ if (routerset_is_empty(old) && routerset_is_empty(new)) {
+ /* Two empty sets are equal */
return 1;
- else if (old == NULL || new == NULL)
+ } else if (routerset_is_empty(old) || routerset_is_empty(new)) {
+ /* An empty set is equal to nothing else. */
return 0;
+ }
+ tor_assert(old != NULL);
+ tor_assert(new != NULL);
if (smartlist_len(old->list) != smartlist_len(new->list))
return 0;