diff options
-rw-r--r-- | src/common/compat.h | 13 | ||||
-rw-r--r-- | src/or/hibernate.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 4 | ||||
-rw-r--r-- | src/or/rephist.c | 6 |
4 files changed, 18 insertions, 7 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index abacce231..fde91172d 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -76,6 +76,19 @@ #endif /* ifndef MAVE_MACRO__func__ */ #endif /* if not windows */ +#if defined(_MSC_VER) && (_MSC_VER < 1300) +/* MSVC versions before 7 apparently don't believe that you can cast uint64_t + * to double and really mean it. */ +extern inline double U64_TO_DBL(uint64_t x) { + int64_t i = (int64_t) x; + return (i < 0) ? ((double) INT64_MAX) : (double) i; +} +#define DBL_TO_U64(x) ((uint64_t)(int64_t) (x)) +#else +#define U64_TO_DBL(x) ((double) (x)) +#define DBL_TO_U64(x) ((uint64_t) (x)) +#endif + /* ===== String compatibility */ #ifdef MS_WINDOWS /* Windows names string functions differently from most other platforms. */ diff --git a/src/or/hibernate.c b/src/or/hibernate.c index d4e6ceb07..b41bf44ed 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -683,7 +683,7 @@ hibernate_hard_limit_reached(void) static int hibernate_soft_limit_reached(void) { - uint64_t soft_limit = (uint64_t) ((get_options()->AccountingMax) * .95); + uint64_t soft_limit = DBL_TO_U64((get_options()->AccountingMax) * .95); if (!soft_limit) return 0; return n_bytes_read_in_interval >= soft_limit diff --git a/src/or/main.c b/src/or/main.c index bb562a572..7b2364a4f 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1359,11 +1359,11 @@ dumpstats(int severity) U64_PRINTF_ARG(stats_n_destroy_cells_processed)); if (stats_n_data_cells_packaged) log(severity,LD_NET,"Average packaged cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_packaged) / + 100*(U64_TO_DBL(stats_n_data_bytes_packaged) / (stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) ); if (stats_n_data_cells_received) log(severity,LD_NET,"Average delivered cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_received) / + 100*(U64_TO_DBL(stats_n_data_bytes_received) / (stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) ); if (now - time_of_process_start >= 0) diff --git a/src/or/rephist.c b/src/or/rephist.c index 2459d46b7..3d391ad94 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -577,11 +577,9 @@ rep_hist_bandwidth_assess(void) r = find_largest_max(read_array); w = find_largest_max(write_array); if (r>w) - return (int)(w/(double)NUM_SECS_ROLLING_MEASURE); + return (int)(U64_TO_DBL(w)/NUM_SECS_ROLLING_MEASURE); else - return (int)(r/(double)NUM_SECS_ROLLING_MEASURE); - - return 0; + return (int)(U64_TO_DBL(r)/NUM_SECS_ROLLING_MEASURE); } /** |