From 5e6f05bc31dc4ab28e9e6ec9ca1ab8d44ad21a52 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Jul 2007 20:46:14 +0000 Subject: [PATCH] r13822@catbus: nickm | 2007-07-18 16:43:39 -0400 Tweak a couple of loop-related variables to make the gcc 4.2 -Wstrict-overflow warning happy. svn:r10874 --- src/or/routerlist.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7230f03c4d..67726a5fdf 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1283,7 +1283,7 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, int for_exit, int statuses) /* Last, count through sl until we get to the element we picked */ tmp = 0; - for (i=0; i < smartlist_len(sl); i++) { + for (i=0; i < smartlist_len(sl) && tmp < rand_bw; i++) { if (statuses) { status = smartlist_get(sl, i); is_exit = status->is_exit; @@ -1295,11 +1295,10 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, int for_exit, int statuses) tmp += ((uint64_t)(bandwidths[i] * exit_weight)); else tmp += bandwidths[i]; - if (tmp >= rand_bw) - break; } - if (i == smartlist_len(sl)) { + if (tmp < rand_bw) { /* This is possible due to round-off error. */ + tor_assert(i == smartlist_len(sl)); --i; log_warn(LD_BUG, "Round-off error in computing bandwidth had an effect on " " which router we chose. Please tell the developers."); @@ -2570,8 +2569,8 @@ static void routerlist_remove_old_cached_routers_with_id(time_t cutoff, int lo, int hi, digestmap_t *retain) { - int i, n = hi-lo+1, n_extra; - int n_rmv = 0; + int i, n = hi-lo+1; + unsigned n_extra, n_rmv = 0; struct duration_idx_t *lifespans; uint8_t *rmv, *must_keep; smartlist_t *lst = routerlist->old_routers; @@ -2587,9 +2586,12 @@ routerlist_remove_old_cached_routers_with_id(time_t cutoff, int lo, int hi, #endif /* Check whether we need to do anything at all. */ - n_extra = n - max_descriptors_per_router(); - if (n_extra <= 0) - return; + { + int mdpr = max_descriptors_per_router(); + if (n <= mdpr) + return; + n_extra = n - mdpr; + } lifespans = tor_malloc_zero(sizeof(struct duration_idx_t)*n); rmv = tor_malloc_zero(sizeof(uint8_t)*n);