aboutsummaryrefslogtreecommitdiff
path: root/src/or/dirvote.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-08 11:35:06 -0400
committerNick Mathewson <nickm@torproject.org>2013-07-08 11:35:06 -0400
commitb34279d3ab2bae2a1393427e0866da018cf8b678 (patch)
treea614f2c4e738eba50ed61613945f1a8ce0ff6191 /src/or/dirvote.c
parent15cd79f83232d8be84992f809cd1951939d1d5ee (diff)
downloadtor-b34279d3ab2bae2a1393427e0866da018cf8b678.tar
tor-b34279d3ab2bae2a1393427e0866da018cf8b678.tar.gz
Add a comment and a check for why flag indices will be <= 63
Diffstat (limited to 'src/or/dirvote.c')
-rw-r--r--src/or/dirvote.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 7537fb8b2..e0af66e22 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -1590,10 +1590,19 @@ networkstatus_compute_consensus(smartlist_t *votes,
unnamed_flag[i] = named_flag[i] = -1;
chosen_named_idx = smartlist_string_pos(flags, "Named");
- /* Build the flag index. */
+ /* Build the flag indexes. Note that no vote can have more than 64 members
+ * for known_flags, so no value will be greater than 63, so it's safe to
+ * do U64_LITERAL(1) << index on these values. But note also that
+ * named_flag and unnamed_flag are initialized to -1, so we need to check
+ * that they're actually set before doing U64_LITERAL(1) << index with
+ * them.*/
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
flag_map[v_sl_idx] = tor_malloc_zero(
sizeof(int)*smartlist_len(v->known_flags));
+ if (smartlist_len(v->known_flags) > MAX_KNOWN_FLAGS_IN_VOTE) {
+ log_warn(LD_BUG, "Somehow, a vote has %d entries in known_flags",
+ smartlist_len(v->known_flags));
+ }
SMARTLIST_FOREACH_BEGIN(v->known_flags, const char *, fl) {
int p = smartlist_string_pos(flags, fl);
tor_assert(p >= 0);