diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:59:21 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:59:21 -0400 |
commit | 59f9a5c78695213442599e8f2e8a535e8a9cc666 (patch) | |
tree | 685a37f894dabb4368117e181fa83205dcdc5bea /src/or/routerlist.c | |
parent | 5126bc2ebd9ae67449e3c4f18828acb895d86308 (diff) | |
download | tor-59f9a5c78695213442599e8f2e8a535e8a9cc666.tar.gz tor-59f9a5c78695213442599e8f2e8a535e8a9cc666.zip |
Avoid divide by zero and NaNs in scale_array_elements_to_u64
Patch from teor; part of 13104
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 32cbe19379..0df411b822 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1802,7 +1802,7 @@ scale_array_elements_to_u64(u64_dbl_t *entries, int n_entries, uint64_t *total_out) { double total = 0.0; - double scale_factor; + double scale_factor = 0.0; int i; /* big, but far away from overflowing an int64_t */ #define SCALE_TO_U64_MAX (INT64_MAX / 4) @@ -1810,7 +1810,8 @@ scale_array_elements_to_u64(u64_dbl_t *entries, int n_entries, for (i = 0; i < n_entries; ++i) total += entries[i].dbl; - scale_factor = SCALE_TO_U64_MAX / total; + if (total > 0.0) + scale_factor = SCALE_TO_U64_MAX / total; for (i = 0; i < n_entries; ++i) entries[i].u64 = tor_llround(entries[i].dbl * scale_factor); |