summaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-06-13 11:25:19 -0400
committerNick Mathewson <nickm@torproject.org>2016-06-13 11:25:19 -0400
commit4c90cdc0e7850a1a97ce064fc1496e6dc258fc0a (patch)
tree269307b34c85445c071e1952022d8b32aec7142c /src/or/routerlist.c
parent6a7d11f38a01b315fb5d7da9ad1d271991d2644e (diff)
downloadtor-4c90cdc0e7850a1a97ce064fc1496e6dc258fc0a.tar.gz
tor-4c90cdc0e7850a1a97ce064fc1496e6dc258fc0a.zip
Coverity dislikes (double) (int/int).
When you divide an int by an int and get a fraction and _then_ cast to double, coverity assumes that you meant to cast to a double first. In my fix for -Wfloat-conversion in 493499a3399f8a8532b4b2a80006, I did something like this that coverity didn't like. Instead, I'm taking another approach here. Fixes CID 1232089, I hope.
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 46492c571f..aaa8fad178 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -2176,22 +2176,20 @@ scale_array_elements_to_u64(uint64_t *entries_out, const double *entries_in,
double total = 0.0;
double scale_factor = 0.0;
int i;
- /* big, but far away from overflowing an int64_t */
-#define SCALE_TO_U64_MAX ((double) (INT64_MAX / 4))
for (i = 0; i < n_entries; ++i)
total += entries_in[i];
- if (total > 0.0)
- scale_factor = SCALE_TO_U64_MAX / total;
+ if (total > 0.0) {
+ scale_factor = ((double)INT64_MAX) / total;
+ scale_factor /= 4.0; /* make sure we're very far away from overflowing */
+ }
for (i = 0; i < n_entries; ++i)
entries_out[i] = tor_llround(entries_in[i] * scale_factor);
if (total_out)
*total_out = (uint64_t) total;
-
-#undef SCALE_TO_U64_MAX
}
/** Pick a random element of <b>n_entries</b>-element array <b>entries</b>,